Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q: 1 ( Answer ) import pandas as pd def import _ data ( csv _ filename ) : Import data from

Q:1(Answer)
import pandas as pd
def import_data(csv_filename):
"""
Import data from a CSV file into a pandas DataFrame.
Parameters:
csv_filename (str): File path for the CSV file.
Returns:
pandas.DataFrame: DataFrame containing the imported data.
"""
# Read the CSV file into a DataFrame
df = pd.read_csv(csv_filename, sep=",", header=0, index_col=None)
return df
# Example usage:
df = import_data("superstore_data.csv")
print(df.head()) # Display the first few rows of the DataFrame
Question: 4(Answer)
import pandas as pd
def compute_profit_per_dollar_sold(df):
# Calculate profit per dollar sold
df['profit_per_dollar_sold']= df['Profit']/ df['Sales']
# Return the dataframe with the new column
return df
# Example of usage:
# Assuming df is your pandas dataframe with columns "Profit" and "Sales"
new_df = compute_profit_per_dollar_sold(df)
Question 5:
Objective: Compute statistics on a variable/column Create a function called compute_mean value that receives as input two arguments: a dataframe and the name of a column. If the column refers to a numeric type (int64 or f loat64), it should return the column average otherwise return a -1. Return the average rounded to two decimals. Hint: E.g., to check if column Profit in the dataframe from question 1 is of type float64, use df[Profit].dtype==float64 Example of usage: mean_value = compute_mean(new_df, "Profit"), where new_df is the dataframe from question 4 should return 28.66.
mean_value = compute_mean(df, "Product Name"), where new_df is the dataframe from question 4 should return -1.
Answer questions 5 separately using the question answers from q1 and Q4

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro PowerShell For Database Developers

Authors: Bryan P Cafferky

1st Edition

1484205413, 9781484205419

More Books

Students also viewed these Databases questions

Question

=+e) About what percent of people should have IQ scores above 132?

Answered: 1 week ago

Question

Differentiate between intelligence testing and achievement testing.

Answered: 1 week ago