Search code examples
pandasdataframemergetime-seriesmultiple-columns

Pandas Dataframe Not Displaying Column Elements


I merged two dataframes but the resulting dataframe is giving back an empty column. How can this be resolved?

print(resampled_fd)
                   Time  power(dB)
0   2021-12-11 10:00:00     46.612
1   2021-12-11 10:02:00     46.902
2   2021-12-11 10:04:00     46.362
3   2021-12-11 10:06:00     47.902
print(df)
                   Time Z(dB)
0   1900-01-01 10:02:00 NaN
1   1900-01-01 10:04:00 NaN
2   1900-01-01 10:06:00 NaN
3   1900-01-01 10:08:00 NaN
dfc=pd.merge(df, resampled_fd)
pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
print(dfc)```

Empty DataFrame
Columns: [Time, Z(dB), power(dB)]
Index: []

Solution

  • Did you mean concatenate instead of merge? If so, you can do:

    df1 = pd.DataFrame({'Time': list('abc'), 'power': list('def')})
    df2 = pd.DataFrame({'Time': list('ghi'), 'Z': list('jkl')})
    pd.concat([df1, df2.rename(columns={'Z': 'power'})], ignore_index=True)
    

    Output:

    Time    power
    0   a   d
    1   b   e
    2   c   f
    3   g   j
    4   h   k
    5   i   l