0

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.

skurring
  • 9
  • 4
  • Your question contains a lot of overhead that probably no one understands. So, if you want to get answers, try to boil it down to a small [mre](https://stackoverflow.com/help/minimal-reproducible-example) (also look [here](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples)) that replicates your problem s.t. other can see it too. – Timus Apr 11 '22 at 10:17
  • I was trying to provide clarity by sharing a lot of details. I see how that can be counterproductive. I've edited the post to be more clear. Thanks for the tip. – skurring Apr 11 '22 at 10:53
  • Not trying to bother you, but it would be best to have small samples of `kline_df` and `rsi.df` _before_ the `pd.concat` that would produce the behaviour you don't want to see. (My suspicion is that you're looking at a part of the result in which the original `kline_df` just hasn't values - the tail, but that's pure speculation and might be completely off.) – Timus Apr 11 '22 at 11:03
  • Not a bother. I'm new to posting on this platform and it's useful having someone show me the ropes like you are. I've edited the original post again, this time with better samples. As can be seen in both dataframes is that the time matches. There should be values there. They definitely get lost somewhere! – skurring Apr 11 '22 at 13:43
  • Could you try `kline_df = pd.concat([kline_df, rsi.df], axis=1)`, to make sure you concat along the columns axis? – Timus Apr 11 '22 at 13:55

0 Answers0