-1
I am trying to create a new data column in pandas format based on two other dataframes.
This first dataset is where I get the values:
GenPart_pdgID =
0 1 2 3 4 5 6 7 8 9 10 11 12 13
0 -4 4 23 23 23 23 23.0 -11.0 11.0 11.0 22.0 -11.0 -4.0 -413.0
1 1 -1 23 23 23 -11 11.0 2.0 21.0 -3.0 11.0 -11.0 11.0 -11.0
2 -1 1 23 21 23 21 23.0 22.0 -13.0 13.0 21.0 21.0 NaN NaN
3 -1 1 23 21 23 21 23.0 23.0 23.0 -13.0 13.0 13.0 22.0 -13.0
4 2 21 23 2 23 23 23.0 23.0 23.0 -11.0 11.0 -11.0 22.0 11.0
... .. .. .. .. .. .. ... ... ... ... ... ... ... ...
2734 3 -3 23 23 -11 11 11.0 22.0 -11.0 3.0 -3.0 11.0 -11.0 NaN
2735 1 -1 23 23 23 23 23.0 -13.0 13.0 NaN NaN NaN NaN NaN
2736 2 -2 23 23 -11 11 22.0 22.0 -11.0 -11.0 22.0 11.0 NaN NaN
2737 -2 21 23 -2 23 23 -13.0 13.0 3.0 -1.0 1.0 -1.0 -2.0 221.0
The second, will contain two columns with the same row numbers as the dataset GenPart_pdgID
:
ele_genIdx =
0 1
0 9.0 11.0
1 NaN NaN
2 NaN NaN
3 NaN NaN
4 13.0 11.0
... ... ...
2733 NaN NaN
2734 8.0 6.0
2735 NaN NaN
2736 -1.0 NaN
2737 NaN NaN
That is, the first column of ele_genIdx
will map which column to take inside the dataframe GenPart_pdgID
. For example, line 0 and line 4 contain values 9 and 13 respectively, thus in the dataframe GenPart_pdgID
I’ll take his line 0 with column 9 and then row 4 with column 13 and so on.
Note: In the case of lines that contain Nan, I want you to return nothing, since it contains no value
Thank you so much for the answer. In fact this dataset is small, but I work with a number of other datasets with various entries. Anyway, I’ll try to use what you sent. Thanks again
– matheus macedo