Skip to content
Advertisement

Tag: dataframe

Too many indices for array | python

I’m trying to copy arrays to a pandas Dataframe and get the error “too many indices for array”. The error occurs in these lines: pr_daily and rad_daily are numpy arrays of of the same length. Traceback (most recent call last): File “C:Users…Downloadspython_scriptspv.py”, line 277, in finalDataframe[f’pr_{a_id[index]}’] = (pr_daily[:,index]) IndexError: too many indices for array Answer This error is thrown when

Better (maybe more SQL-ish) way to populate pandas dataframe column from row and meta data than iterating over rows, please

My data looks like this: Because I used a pandas.groupby() process to generate my metadata, it looks like this: Now, if my metadata looked like: I could easily write: I feel that there should be a different, pandas-oriented, way to directly use the metadata in the meta_df dataframe format that I have, and that it’ll probably be more efficient than

Mapping from a different dataframe

I have a dataset of patients, e.g.: and a dataset of diseases of each patient (by ICD code): How can I flag each patient if he had history of a specific ICD code, desired output: I am currently doing it with iteration but this takes too long…. Answer If need indicators – it means only 0, 1 values use get_dummies:

Advertisement