Lab 3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

LAB-3: Python Pandas and Data Frames

Practice Questions

You can use the Retail dataset from Kaggle for this exercise.
https://www.kaggle.com/datasets/vijayuv/onlineretail

Scenario

You are a data analyst at an e-commerce company. The company has provided you with a dataset
containing information about customer orders, including the invoice number, stock code, description,
quantity, invoice date, unit price, customer ID, and country. Your task is to analyze this data to gain
insights into customer behavior, product performance, and sales trends.

Questions

1. Loading Data:

o How would you load the dataset into a Pandas DataFrame? Provide the code to read
the CSV file.

2. Basic Data Exploration:

o What methods can you use to display the first few rows and the summary statistics
of the DataFrame? Provide the code to display the first 10 rows of the data frame,
and the summary statistics of the resultant data frame.

3. Selecting Data with iloc and loc methods:

o Write the code to select the first 10 rows of the DataFrame using the iloc method?

o Write the code to select all orders from a specific customer ID using the loc method?

4. Filtering Data:

o Write a code to filter the DataFrame to show only the orders where the quantity is
greater than 50.

5. Sorting Data:

o Write a code to sort the DataFrame by the unit price in descending order using the
sort_by method.

6. Grouping and Aggregation:

o Using the group_by method, how can you calculate the total quantity of products
ordered for each stock code?

7. Merging DataFrames:

o Suppose you have another DataFrame with customer details (customer ID, customer
name, customer segment). Write a code to merge this DataFrame with the main
DataFrame on the customer ID column?
8. Joining DataFrames:

o Explain the difference between merging and joining DataFrames. Provide an example
of joining two DataFrames on a common column.

9. Concatenating DataFrames:

o How would you concatenate two DataFrames vertically? Provide an example.

10. Data Manipulation:

o Write a code to create a new column that represents the total price for each order
(quantity multiplied by unit price).

o How can you use the loc method to update the description of a specific stock code to
"Updated Description"?

You might also like