educative.io

Educative

Trying to work through Exploring Numerical Quantities - check my code

import pandas as pd

df = pd.read_csv(‘credit_card_cleaned.csv’)

Write your code here

custom_bins = [0,100000,200000]

binned = pd.cut(df[‘LIMIT_BAL’],bins = custom_bins)

print(binned.head())

df[‘BL’] = binned

x = df.groupby([‘BL’,‘LIMIT_BAL’]).size()

x = x.unstack()

print(x)

Hi @olivia1,

This is Maham Amjad from Educative. I noticed your feedback here, and I’m glad you reached out to us.

I checked your code. There are two things I’ll like to highlight:

  1. You created the bins successfully. Nice Job!
  2. The problem lies in grouping the data.

If you reread the first question, it states, " How many people lie in the interval (0, 100000] of ‘LIMIT_BAL’ who have defaulted?" So you shouldn’t group the data again with ‘LIMIT_BAL’. This column (according to the question) should create the bins only. Grouping is to be done by a column that contains the default-payment information. According to the details of the dataset given at the start of the lesson, that column is: ‘default.payment.next.month’. It will correctly group your data, and you can proceed with the next questions successfully.

Please feel free to reach out if you have any other queries or concerns.

Best Regards,
Maham Amjad| Developer Advocate
Educative Inc.