我有两个数据帧,其中包含来自两个银行帐户的交易。我只想把它们组合成一个数据帧。不过,这对我来说效果不太好。数据帧称为df
和JLcard
,下面是一些信息
df.shape
(1405, 3)
JLcard.shape
(96, 3)
df.columns
Index([u'Transaction_Type', u'Transaction_Description', u'transaction'], dtype='object')
JLcard.columns
Index([u'Transaction_Description', u'transaction', u'Transaction_Type'], dtype='object')
因此,如果两个数据帧的顺序不同,它们的列名是相同的。在
也有按日期索引的。在
^{pr2}$为了将它们组合成一个数据帧,我尝试了pd.concat([df,JLcard])
,这给了我:
FutureWarning: Sorting because non-concatenation axis is not aligned. A future version
of pandas will change to not sort by default.
To accept the future behavior, pass 'sort=True'.
To retain the current behavior and silence the warning, pass sort=False
"""Entry point for launching an IPython kernel.
生成的数据帧也不按索引排序。E、 g
Transaction_Description Transaction_Type transaction
date
2018-04-10 ES DEB -16.57
2018-04-04 OR Js card 109.30
2018-04-05 WR Js card 125.00
Why does it say the "non-concatenation axis is not aligned"? Why does it say it is sorting when it doesn't seem to be? And what could I do to avoid the warning? I simply want to copy all the rows from one into the other and sort by the index (which is the date).
你可以试试
pd.merge(f,JLcard,left_index=True, right_index=True)
相关问题 更多 >
编程相关推荐