I Have a pandas dataframe with int unique values from 0 to 4.
df.head()
Labels
Date
2020-01-02 0
2020-01-03 0
2020-01-06 1
2020-01-07 2
2020-01-08 2
I have a numpy array
np_arr
array([[12., 17., 10., 3.],
[10., 23., 9., 6.],
[16., 9., 5., 9.],
[17., 22., 14., 9.],
[19., 14., 10., 8.]])
I Have another null dataframe with same shape as df.
df_final.head()
col_0 col_1 col_2 col_3
Date
2020-01-02 0.0 0.0 0.0 0.0
2020-01-03 0.0 0.0 0.0 0.0
2020-01-06 0.0 0.0 0.0 0.0
2020-01-07 0.0 0.0 0.0 0.0
2020-01-08 0.0 0.0 0.0 0.0
I would like to use apply on df_final to replace row values from np_arr based on the Labels value of dataframe df.
For ex:
if df.values[0]=x:
df_final.values[0]=np_arr[x]
Thank you for your help.