'pandas concat looses information

Since Pandas is removing dataframe appending, I'm trying to concat two dataframes. I've managed to concat two Pandas dataframes. The unexpected behaviour starts coming when try to concat a Pandas dataframe which is returned by the btalib module.

My first dataframe is Binance historical kline data.

import asyncio, btalib
from datetime import datetime
from binance import AsyncClient, BinanceSocketManager

print(kline_df.tail())
print(type(kline_df))

                      open   high    low  close    symbol
date
2022-04-11 13:36:00  14.02  14.09  14.01  14.09       NaN
2022-04-11 13:37:00  14.09  14.10  14.05  14.06       NaN
2022-04-11 13:38:00  14.06  14.07  14.02  14.02       NaN
2022-04-11 13:39:00  14.01  14.02  14.00  14.02       NaN
2022-04-11 13:39:00  14.01  14.03  14.00  14.02  LINKUSDT
<class 'pandas.core.frame.DataFrame'>

rsi = btalib.rsi(kline_df['close'], period=14)
print(rsi.df)
print(type(rsi.df)

                           rsi
date
2022-04-11 13:36:00  55.557897
2022-04-11 13:37:00  49.370771
2022-04-11 13:38:00  42.564433
2022-04-11 13:39:00  42.564433
2022-04-11 13:39:00  42.564433
<class 'pandas.core.frame.DataFrame'>

When I perform technical analysis on the dataframe with btalib I start loosing information.

kline_df = pd.concat([kline_df, rsi.df])
print(kline_df.tail())

                     open  high  low  close symbol        rsi
date
2022-04-11 13:36:00   NaN   NaN  NaN    NaN    NaN  55.557897
2022-04-11 13:37:00   NaN   NaN  NaN    NaN    NaN  49.370771
2022-04-11 13:38:00   NaN   NaN  NaN    NaN    NaN  42.564433
2022-04-11 13:39:00   NaN   NaN  NaN    NaN    NaN  42.564433
2022-04-11 13:39:00   NaN   NaN  NaN    NaN    NaN  42.564433

What should I do to fix this?

Thanks in advance for taking the time to read and reply to this.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source