Menu

Your First Data Science Analysis in Python

Your First Data Science Analysis in Python

Now combine the concepts from this module in a small example.

Suppose a shop wants to analyze its sales for five products. You can use Pandas to organize the data, calculate a total, identify the best-selling product by revenue, and create a chart.

Step 1: Create the Dataset

The DataFrame contains two columns: product names and sales values.

Step 2: Calculate Total Sales

total_sales = df["Sales"].sum()
print("Total Sales:", total_sales)

Output:

Total Sales: 120000

This calculation adds the sales values across all five products.

Step 3: Identify the Highest-Revenue Product

top_product = df.loc[df["Sales"].idxmax()]
print("Top Product:", top_product["Product"])
print("Sales:", top_product["Sales"])

Output:

Top Product: Laptop

Sales: 50000

The idxmax() method returns the index of the largest value in the selected Series. The loc accessor uses that index to retrieve the corresponding row.

Step 4: Visualize the Sales

import matplotlib.pyplot as plt
plt.figure(figsize=(8, 5))
plt.bar(df["Product"], df["Sales"])
plt.title("Product Sales Analysis")
plt.xlabel("Product")
plt.ylabel("Sales Amount")
plt.xticks(rotation=30)
plt.tight_layout()
plt.show()

The resulting bar chart compares revenue across the five products.

Step 5: Interpret the Results

The analysis reveals that total sales equal 120,000 units of currency, and the laptop category has the highest sales value in this sample.

These results describe the provided data. They do not establish which product is the most profitable because costs have not been included.

This example demonstrates a basic data science workflow: create structured data, calculate metrics, visualize results, and interpret the findings in context.

As you progress through the tutorial, you will replace small manually created datasets with files and larger datasets, apply more advanced transformations, and explore statistical analysis and machine learning.


Python for Data Science

VA

Vishalini A



Learn via Video Course

undefined Logo

NaN hrs



Get in Touch For Details