Question: In [ 3 1 ] : import pandas as pd # Create a DataFrame with balance.txt df = pd . read _ csv (
In :
import pandas as pd
# Create a DataFrame with balance.txt
df pdreadcsvbalancetxt sep
Compare the average income based on ethnicity
printAverage income by ethnicity:"
averageincomebyethnicity dfgroupbyEthnicityIncomemeanround
printaverageincomebyethnicity
# On average, do married or single people have a higher balance?
# Calculate the average balance of married people
averagebalancemarried dfdfMarried "Yes"Balancemean round
print
Average balance of married person:", averagebalancemarried
# Calculate the average balance of single people
averagebalancesingle "Married"NoBalancemeanround
printAverage balance of single person:", averagebalancesingle
# Check if balance of married person balance of unmarried person
if averagebalancemarried averagebalancesingle:
print
Married people have a higher balance than single people.
elif averagebalancesingle averagebalancemarried:
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?
highestincome "Income"round
print
Highest income:", highestincome
# What is the lowest income in our dataset?
lowestincome "Income"minround
printLowest income:", lowestincome
# How many cards do we have recorded in our dataset?
totalcards "Cards" :sum
print
Total number of cards:", totalcards
How many females and males do we have information for?
gendercounts "Gender"valuecounts
print
Number of females and males:"
printgendercounts
Average income by ethnicity:
Ethnicity
African American
Asian
Caucasian
Name: Income, dtype: float
Average balance of married person:
Average balance of single person:
single people have a higher balance than married people.
AttributeError
Traceback most recent call last
Cell In line
else: print
Balances are equal for married and single people.
# What is the highest income in our dataset?
highestincome "Income" max round
print
Highest income:", highestincome
# What is the lowest income in our dataset?
AttributeError: 'float' object has no attribute 'round'
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
