将两个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的,虽然不太懂其中的原因,但效果确实是这样的~

你可能感兴趣的:(Python,计算机基础,数据处理)