Extracting index from a dataframe and appening to another dataframe

30 views Asked by At

I have a DataFrame as follows:

aa
              Low_value            High_value
0              0.005450              0.005950
1              0.358575              0.441125
2              0.020050              0.022950
3              0.625275              0.753225

There is another DataFrame as shown below:

bb

Type1  0.0056  ...  0.0046
Type2  0.2850  ...  0.3246
Type3  0.0134  ...  0.0137
Type4  0.0056  ...  0.0046

I want to extract the index column of bb and append it to aa so that the new aa looks as below:

new_aa

                  Low_value            High_value
Type1              0.005450              0.005950
Type2              0.358575              0.441125
Type3              0.020050              0.022950
Type4              0.625275              0.753225

I extracted the index of bb as follows and then tried to reindex aa, but all the values in the columns are replaced with NaN.

Index = bb.index
aa.reindex(Index)

Thanks in advance.

1

There are 1 answers

0
Ujjwal Agrawal On
aa["bb_index"] = bb.index

aa.set_index("bb_index" ,drop = True)

This must work