neuniversity / ALY6140

1 stars 3 forks source link

Sorting and with groupby #42

Open ThatkidfromA opened 5 years ago

ThatkidfromA commented 5 years ago

Hi guys,

Im experiencing NAN result from applying below argument:

df1['OWN_OCC'] =df1['OWN_OCC'].map({'Y': 1,'N': 0}) df_12 = df1.sort_values('OWN_OCC', ascending = False). groupby('GROSS_TAX').head(1) df_12 #Showing the result.

In column own_occ, the variables are Y (Yes) and N (No) and I want to change the variable into 1 and 0. The result of 1 and 0 should be in a new column, but I am receiving NaN value.

How to change the Nan result into 1 and 0?

kn1510 commented 5 years ago

Hi, You can try below code to change value of column to 1 and 0 from Y and N resp.

df1['OWN_OCC'].replace('N', 0, inplace=True) df1['OWN_OCC'].replace('Y', 1, inplace=True)

Let me know if this work for you.

Best, Kalyani

ThatkidfromA commented 5 years ago

Hi, This has work for me. Thank you