Question: In [ 3 1 ] : import pandas as pd # Create a DataFrame with balance.txt df = pd . read _ csv (

In [31]:
import pandas as pd
# Create a DataFrame with balance.txt
df = pd.read_csv("balance.txt", sep ="??s+)
Compare the average income based on ethnicity
print("Average income by ethnicity:")
average_income_by_ethnicity = df.groupby("Ethnicity")["Income"].mean().round(2)
print(average_income_by_ethnicity)
# On average, do married or single people have a higher balance?
# Calculate the average balance of married people
average_balance_married = df[df["Married"]== "Yes"]["Balance"].mean(). round(2)
print("
Average balance of married person:", average_balance_married)
# Calculate the average balance of single people
average_balance_single "Married"]=="No"]["Balance"].mean().round(2)
print("Average balance of single person:", average_balance_single)
# Check if balance of married person > balance of unmarried person
if average_balance_married > average_balance_single:
print('
Married people have a higher balance than single people.')
elif average_balance_single > average_balance_married:
print('
single people have a higher balance than married people.')
else: print('
Balances are equal for married and single people.')
# What is the highest income in our dataset?
highest_income "Income"]*max().round(2)
print("
Highest income:", highest_income)
# What is the lowest income in our dataset?
lowest_income "Income"].min().round(2)
print("Lowest income:", lowest_income)
# How many cards do we have recorded in our dataset?
total_cards "Cards" {:??].sum()
print("
Total number of cards:", total_cards)
How many females and males do we have information for?
gender_counts "Gender"].value_counts ()
print("
Number of females and males:")
print(gender_counts)
Average income by ethnicity:
Ethnicity
African American 47.68
Asian 44.19
Caucasian 44.52
Name: Income, dtype: float64
Average balance of married person: 13.39
Average balance of single person: 13.49
single people have a higher balance than married people.
AttributeError
Traceback (most recent call last)
Cell In[31], line 29
26 else: print('
Balances are equal for married and single people.')
28 # What is the highest income in our dataset?
--->29 highest_income "Income"]. max()* round(2)
30 print("
Highest income:", highest_income)
32 # What is the lowest income in our dataset?
AttributeError: 'float' object has no attribute 'round'
 In [31]: import pandas as pd # Create a DataFrame with

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!