Panda Exercise - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Panda Exercise (/thread-35029.html) |
Panda Exercise - nyzs92 - Sep-24-2021 Hi guys, New here to this forum! I receive this error message "ValueError: If using all scalar values, you must pass an index" and have no idea why it happened. I tried googling it and I do not understand the explanation or even the cause of it. I've just started learning coding, will deeply appreciate if your explanation will be easy for beginners to understand. I tried to attach the CSV file but the file is too large. The questions is this: "Find out the percentage of male patients, visiting different hospitals, and then find out which hospital has the highest percentage. Remember to exclude 'KKH' hospital, as this 'KKH' hospital only treats, female and children patients." noKKH=df['Hospital_Name']!= 'KKH' male_patient=df['Gender']=='M' hos_filt=noKKH & male_patient uni_hospital=(df.loc[hos_filt])['Hospital_Name'].unique() df_filt=df.loc[hos_filt] output={} for hosp in uni_hospital: output.update({str(hosp):list()}) for i in range(len(uni_hospital)): cond = (df_filt['Hospital_Name']==uni_hospital[i]) dfsubset = df_filt.loc[cond].copy() dfs_prop = dfsubset["Gender"].value_counts(normalize=True) output[uni_hospital[i]] = dfsubset result=pd.DataFrame(output) resultAnd this is the error:
|