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."
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:
Error:---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-89-eeebee63cac1> in <module>
16
17
---> 18 result=pd.DataFrame(output)
19 result
~\anaconda3\lib\site-packages\pandas\core\frame.py in __init__(self, data, index, columns, dtype, copy)
527
528 elif isinstance(data, dict):
--> 529 mgr = init_dict(data, index, columns, dtype=dtype)
530 elif isinstance(data, ma.MaskedArray):
531 import numpy.ma.mrecords as mrecords
~\anaconda3\lib\site-packages\pandas\core\internals\construction.py in init_dict(data, index, columns, dtype)
285 arr if not is_datetime64tz_dtype(arr) else arr.copy() for arr in arrays
286 ]
--> 287 return arrays_to_mgr(arrays, data_names, index, columns, dtype=dtype)
288
289
~\anaconda3\lib\site-packages\pandas\core\internals\construction.py in arrays_to_mgr(arrays, arr_names, index, columns, dtype, verify_integrity)
78 # figure out the index, if necessary
79 if index is None:
---> 80 index = extract_index(arrays)
81 else:
82 index = ensure_index(index)
~\anaconda3\lib\site-packages\pandas\core\internals\construction.py in extract_index(data)
389
390 if not indexes and not raw_lengths:
--> 391 raise ValueError("If using all scalar values, you must pass an index")
392
393 if have_series:
ValueError: If using all scalar values, you must pass an index