python - Why am I not able to drop values within columns on pandas using python3? -
i have dataframe (df) various columns. in assignment have find difference between summer gold medals , winter gold medals, relative total medals, each country using stats olympics. must include countries have @ least 1 gold medal. trying use dropna() not include countries not @ least have 1 medal. current code:
def answer_three(): df['medal_count'] = df['gold'] - df['gold.1'] df['medal_count'].dropna() df['medal_dif'] = df['medal_count'] / df['gold.2'] df['medal_dif'].dropna() return df.head() print (answer_three()) this results in following output:
# summer gold silver bronze total # winter gold.1 \ afghanistan 13 0 0 2 2 0 0 algeria 12 5 2 8 15 3 0 argentina 23 18 24 28 70 18 0 armenia 5 1 2 9 12 6 0 australasia 2 3 4 5 12 0 0 silver.1 bronze.1 total.1 # games gold.2 silver.2 bronze.2 \ afghanistan 0 0 0 13 0 0 2 algeria 0 0 0 15 5 2 8 argentina 0 0 0 41 18 24 28 armenia 0 0 0 11 1 2 9 australasia 0 0 0 2 3 4 5 combined total id medal_count medal_dif afghanistan 2 afg 0 nan algeria 15 alg 5 1.0 argentina 70 arg 18 1.0 armenia 12 arm 1 1.0 australasia 12 anz 3 1.0 i need rid of both '0' values in "medal_count" , nan in "medal_dif". aware maths/way have written code incorrect solve question, think need start dropping these values? any of above appreciated.
you required pass axis e.g. axis=1 drop function. axis of 0 => row, , 1 => column. 0 seems default.
as can see entire column dropped axis =1

Comments
Post a Comment