Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I wrote the code below produce a report in Jupyter notebook that provides the following information. Please could someone help refine this with following points:

I wrote the code below produce a report in Jupyter notebook that provides the following information. Please could someone help refine this with following points:
1) how to remove 'Name: Income, dtype: float64' and 'Name: count, dtype: int64'
2) how to round income/ balance numbers to 2 decimal pointsIn [28]: , import pandas as pd
# Create a DataFrame with balance.txt
df = pd.read_csv("balance.txt", sep="\s+")
# 1. Compare the average income based on ethnicity
print("Average income by ethnicity:")
print(df.groupby("Ethnicity")["Income"].mean())
# On average, do married or single people have a higher balance?
# calculate the average balance of married and single person
.Married == "Yes"].loc[:, "Balance"].mean()
print("
Average balance of married person:")
print (bm)
. Married =="No"].loc[:, "Balance"].mean()
print("
Average balance of single person:")
print(bu)
# check if balance of married person > balance of unmarried perosn
if bm> bu:
# if yes, display
print('
Married people have a higher balance than single people.')
# check if balance of unmarried person > balance of married perosn
if bu >bm :
# if yes, display
print('
Single people have a higher balance than married people.')
# What is the highest income in our dataset?
print("
Highest income:")
print(df["Income"].max())
# What is the lowest income in our dataset?
print("
Lowest income:")
print(df["Income"].min())
# How many cards do we have recorded in our dataset?
print("
Total number of cards:")
print(df["Cards"].sum())
# How many females do we have information for vs how many males?
print("
Number of females and males:")
print(df["Gender"].value_counts())
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions