0% found this document useful (0 votes)
16 views8 pages

Rajendra Reddy Task 3

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

Rajendra Reddy Task 3

material
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

7/11/24, 1:34 DS_Task3

PM

Name : AKKALA RAJENDRA REDDY

Roll No : 21F01A0503
College : ST.ANN'S COLLEGE OF ENGINEERING AND TECHNOLOGY

Mail id : [email protected]

Course : Datascience

Task No : Task 3

1) Plot the count of males and females in the dataset

import pandas as pd
import matplotlib.pyplot as plt

gender_counts = df['Gender'].value_counts()
plt.figure(figsize=(8, 6))
plt.bar(gender_counts.index, gender_counts.values, color=['blue', 'pink'])
plt.title('Count of Males and Females')
plt.xlabel('Gender')
plt.ylabel('Count')
plt.show()

2) Sum of amounts spent by each gender and plot the corresponding graph

amount_spent_by_gender = df.groupby('Gender')['Amount Spent'].sum()


plt.figure(figsize=(8, 6))
amount_spent_by_gender.plot(kind='bar', color=['blue', 'pink'])
plt.title('Amount Spent by Gender')
plt.xlabel('Gender')
plt.ylabel('Amount Spent')
plt.xticks(rotation=0)

https://colab.research.google.com/drive/1dfGzSQeAhMxqDr2Yj5V8w-3LV3X6oZof#scrollTo=zHnKqEVmyH1N&printMode=true 1/8
7/11/24, 1:34 DS_Task3
PM plt.show()

3) Count each age group and provide individual counts grouped by gender

age_group_counts = df.groupby(['Age', 'Gender']).size().unstack()


print("Count of each age group grouped by gender:")
print(age_group_counts)

Count of each age group grouped by gender:


Gender Female Male
Age
25 NaN 1.0
30 2.0 NaN
35 1.0 1.0
40 1.0 1.0
45 1.0 1.0
50 NaN 1.0

4) Plot the total amount spent by each age group

amount_spent_by_age_group = df.groupby('Age')['Amount Spent'].sum()


plt.figure(figsize=(10, 6))
amount_spent_by_age_group.plot(kind='bar')
plt.title('Total Amount Spent by Age Group')
plt.xlabel('Age Group')
plt.ylabel('Total Amount Spent')
plt.xticks(rotation=45)
plt.show()

https://colab.research.google.com/drive/1dfGzSQeAhMxqDr2Yj5V8w-3LV3X6oZof#scrollTo=zHnKqEVmyH1N&printMode=true 2/8
7/11/24, 1:34 DS_Task3
PM

5) Plot the total number of orders from the top 10 states

top_10_states = df['State'].value_counts().head(10)
plt.figure(figsize=(10, 6))
top_10_states.plot(kind='bar')
plt.title('Total Orders from Top 10 States')
plt.xlabel('State')
plt.ylabel('Number of Orders')
plt.xticks(rotation=45)
plt.show()

https://colab.research.google.com/drive/1dfGzSQeAhMxqDr2Yj5V8w-3LV3X6oZof#scrollTo=zHnKqEVmyH1N&printMode=true 3/8
7/11/24, 1:34 DS_Task3
PM

6) Determine the total amount spent in the top 10 states

total_amount_spent_top_10_states = df.groupby('State')['Amount Spent'].sum().nlargest(10)


plt.figure(figsize=(10, 6))
total_amount_spent_top_10_states.plot(kind='bar')
plt.title('Total Amount Spent in Top 10 States')
plt.xlabel('State')
plt.ylabel('Total Amount Spent')
plt.xticks(rotation=45)
plt.show()

https://colab.research.google.com/drive/1dfGzSQeAhMxqDr2Yj5V8w-3LV3X6oZof#scrollTo=zHnKqEVmyH1N&printMode=true 4/8
7/11/24, 1:34 DS_Task3
PM

7) Plot a comparison graph between the number of married and unmarried


individuals

marital_status_counts = df['Marital Status'].value_counts()


plt.figure(figsize=(8, 6))
plt.bar(marital_status_counts.index, marital_status_counts.values, color=['blue', 'green'])
plt.title('Count of Married and Unmarried Individuals')
plt.xlabel('Marital Status')
plt.ylabel('Count')
plt.show()

https://colab.research.google.com/drive/1dfGzSQeAhMxqDr2Yj5V8w-3LV3X6oZof#scrollTo=zHnKqEVmyH1N&printMode=true 5/8
7/11/24, 1:34 DS_Task3
PM

8) Plot the amount spent by males and females based on marital status

amount_spent_by_gender_marital = df.groupby(['Gender', 'Marital Status'])['Amount Spent'].sum().unstack()


plt.figure(figsize=(10, 6))
amount_spent_by_gender_marital.plot(kind='bar', stacked=True)
plt.title('Amount Spent by Gender and Marital Status')
plt.xlabel('Gender')
plt.ylabel('Amount Spent')
plt.xticks(rotation=0)
plt.legend(title='Marital Status')
plt.show()

<Figure size 1000x600 with 0 Axes>

https://colab.research.google.com/drive/1dfGzSQeAhMxqDr2Yj5V8w-3LV3X6oZof#scrollTo=zHnKqEVmyH1N&printMode=true 6/8
7/11/24, 1:34 DS_Task3
PM
9) Plot the count of each occupation present in the dataset

occupation_counts = df['Occupation'].value_counts()
plt.figure(figsize=(12, 6))
occupation_counts.plot(kind='bar')
plt.title('Count of Each Occupation')
plt.xlabel('Occupation')
plt.ylabel('Count')
plt.xticks(rotation=45)
plt.show()

10) Plot the amount spent by each occupation in descending order

amount_spent_by_occupation = df.groupby('Occupation')['Amount Spent'].sum().sort_values(ascending=False)


plt.figure(figsize=(12, 6))
amount_spent_by_occupation.plot(kind='bar')
plt.title('Amount Spent by Occupation')
plt.xlabel('Occupation')
plt.ylabel('Amount Spent')
plt.xticks(rotation=45)
plt.show()

https://colab.research.google.com/drive/1dfGzSQeAhMxqDr2Yj5V8w-3LV3X6oZof#scrollTo=zHnKqEVmyH1N&printMode=true 7/8
7/11/24, 1:34 DS_Task3
PM

https://colab.research.google.com/drive/1dfGzSQeAhMxqDr2Yj5V8w-3LV3X6oZof#scrollTo=zHnKqEVmyH1N&printMode=true 8/8

You might also like