0% found this document useful (0 votes)
8 views3 pages

Questions

The document outlines ten practice problems focused on using pandas for data inspection, manipulation, and cleaning. Each problem includes specific tasks such as loading datasets, checking for missing values, calculating descriptive statistics, and performing data aggregation. The problems are designed to enhance skills in handling various data-related tasks using pandas.

Uploaded by

subassk121418
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Questions

The document outlines ten practice problems focused on using pandas for data inspection, manipulation, and cleaning. Each problem includes specific tasks such as loading datasets, checking for missing values, calculating descriptive statistics, and performing data aggregation. The problems are designed to enhance skills in handling various data-related tasks using pandas.

Uploaded by

subassk121418
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Sure!

Here are some practice problems focusing on pandas data inspection:

Problem 1: Loading Data and Checking Basic Information

1. Load the dataset sales_data.csv into a pandas DataFrame.

2. Inspect the first 5 rows of the dataset.

3. Get a summary of the DataFrame, including the number of non-null values and the
data types for each column.

4. Check how many unique values exist in each column.

Problem 2: Descriptive Statistics

1. Load the employee_data.csv into a pandas DataFrame.

2. Calculate the following:

o The mean, median, and standard deviation of the salary column.

o The minimum and maximum values of the 'age' column.

3. What is the range of ages in the dataset (i.e., max age - min age)?

Problem 3: Checking for Missing Data

1. Load the customer_data.csv into a pandas DataFrame.

2. Check for missing values in the entire dataset.

3. Identify the columns with missing data and calculate the percentage of missing
values per column.

4. Drop the rows where any of the columns have missing values.

Problem 4: DataFrame Indexing and Slicing

1. Load the [Link] file into a DataFrame.

2. Select the rows where the transaction amount is greater than $1000.

3. Create a subset DataFrame that contains only the columns: transaction_id,


customer_id, amount.

4. Filter out the transactions where the customer is from "Los Angeles."
Problem 5: Value Counts and Frequency Analysis

1. Load the survey_data.csv into a pandas DataFrame.

2. Use value_counts() to determine the frequency of each unique response in the


gender column.

3. In the city column, find out how many people are from each city and return the
result in descending order.

Problem 6: Data Aggregation and Grouping

1. Load the sales_data.csv into a pandas DataFrame.

2. Group the dataset by the product_category and calculate:

o The total sales (sum of the sales_amount).

o The average sales (mean of the sales_amount).

3. Sort the categories by total sales in descending order.

Problem 7: Checking Duplicates

1. Load the students_data.csv into a pandas DataFrame.

2. Check for duplicate rows in the dataset.

3. Drop duplicate rows if any and create a new DataFrame.

4. After dropping duplicates, check how many rows are left in the DataFrame.

Problem 8: Correlation Matrix

1. Load the financial_data.csv into a pandas DataFrame.

2. Generate a correlation matrix for the numeric columns in the dataset.

3. Find the correlation between the revenue and advertising_expense columns.

Problem 9: Data Types and Conversion

1. Load the inventory_data.csv into a pandas DataFrame.

2. Check the data types of all columns.


3. Convert the purchase_date column to a pandas datetime format.

4. Convert the quantity column to integers, if they are not already in integer format.

Problem 10: String Manipulation and Inspection

1. Load the product_info.csv into a pandas DataFrame.

2. In the product_name column, find how many products contain the word "Premium."

3. Extract the first three characters of each product name in the product_name column.

4. Create a new column product_type that contains "Electronics" for any product name
containing the word "Laptop" or "Phone," and "Non-Electronics" otherwise.

These problems will help you sharpen your skills in inspecting, manipulating, and cleaning
datasets in pandas. Would you like help solving any of them?

Common questions

Powered by AI

Use the str accessor for string operations, such as str.contains() to check for specific words and assign specific values to new columns based on these conditions. str.slice() can extract specific parts of strings, like the first few characters .

Use the isnull() method to identify missing data and the sum() method to count them across each column. Calculate the percentage of missing data per column by dividing this sum by the total number of rows and then multiplying by 100 .

Use the corr() method to generate a correlation matrix for numeric columns. To interpret the correlation between two columns, look at the matrix's intersection values, which show correlation coefficients (ranging from -1 to 1).

Use the value_counts() method on a DataFrame column to compute the frequency of each unique response. Sorting the results can help identify the most and least common entries in descending order .

First, load the dataset using pandas’ read_csv() function. To inspect the DataFrame's basic information, use the head() method to view the first few rows, followed by the info() method to get a summary of the DataFrame. This includes the number of non-null values and data types of each column .

Use the duplicated() method to identify duplicate rows. To remove them, use drop_duplicates(), creating a new DataFrame without duplicates. Confirm the changes by checking the row count before and after removal .

Use the to_datetime() function to convert dates to pandas datetime format. For numerical data, use astype() to ensure conversion to integer format. These transformations maintain consistency and allow for accurate calculations .

To filter rows, use conditional indexing. For example, select rows where a column value is greater than a threshold. Then use double brackets with column names to extract specific columns, creating a subset DataFrame .

Use the groupby() function to group data by a specified column. Apply aggregate functions such as sum() for total and mean() for average on the grouped data column. Sort results using the sort_values() method for better readability .

Calculate the range of ages by subtracting the minimum value from the maximum value using the min() and max() functions on the age column: max(age) - min(age).

You might also like