I'm working with Python 3.6.9.
I'm stuck on a dataframe like that :
import pandas as pd
import numpy as np
dict_ = {'col1': [3.14, 28, -0.618, 1.159], 'col2': ['a_002_u', 'a_003_u', 'a_001_u', 'a_003_u'], 'a_001_u': [np.nan] * 4, 'a_002_u': [np.nan] * 4, 'a_003_u': [np.nan] * 4}
df = pd.DataFrame(dict_)
col1 col2 a_001_u a_002_u a_003_u
0 3.140 a_002_u NaN NaN NaN
1 28.000 a_003_u NaN NaN NaN
2 -0.618 a_001_u NaN NaN NaN
3 1.159 a_003_u NaN NaN NaN
And I would like to get this result :
col1 col2 a_001_u a_002_u a_003_u
0 3.140 a_002_u NaN 3.14 NaN
1 28.000 a_003_u NaN NaN 28.000
2 -0.618 a_001_u -0.618 NaN NaN
3 1.159 a_003_u NaN NaN 1.159
In other words, I would like to fill columns 'a_001_u', 'a_002_u', and 'a_003_u' with 'col1' values based on column header in 'col2'.
It is quite easy to explain, but I have the impression that it is less obvious to set up. Does anyone have an idea to help me?