将两个DataFrame拼接起来,除了concat还有append()
也是有趣,我一直在想用concat來實現將兩個dataframe給拼接起來。但是在習慣了 a = a + b 的這樣運算思維之后,用concat心中的苦,恐怕除了我,就只有搜到我這篇文章的你知道了…
concat是不支持這樣的用法的
dfA = pd.concat(dfA, dfB)
pandas.concat(objs, axis=0, join=‘outer’, join_axes=None, ignore_index=False, keys=None, levels=None, names=None, verify_integrity=False, sort=None, copy=True)[source]
-
object是一個關于series, df, panel的list
objs : a sequence or mapping of Series, DataFrame, or Panel objects
If a dict is passed, the sorted keys will be used as the keys argument, unless it is passed, in which case the values will be selected (see below). Any None objects will be dropped silently unless they are all None in which case a ValueError will be raised -
所以應該是 dfA = pd.concat([dfA, dfB])
但是append()支持!!
dfA = dfA.append(dfB) 就是OK的,雖然不太懂其中的原因,但效果確實是這樣的~
總結
以上是生活随笔為你收集整理的将两个DataFrame拼接起来,除了concat还有append()的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: DataFrame关于某一列做归一化处理
- 下一篇: dataframe的重设index