我试图在索引上合并两个熊猫数据帧,但我得到错误。。。在
alleles chrom pos strand assembly# center protLSID assayLSID
rs#
TP121 C/A 0 121 + NaN NaN NaN NaN
TP135 G/A 0 135 + NaN NaN NaN NaN
TP283 A/G 0 283 + NaN NaN NaN NaN
TP302 C/T 0 302 + NaN NaN NaN NaN
TP334 T/G 0 334 + NaN NaN NaN NaN
当我尝试合并时,我得到了这个错误-"['TP121' 'TP135' 'TP283' ..., 'TP251072' 'TP251178' 'TP251355'] not in index"
,当它们明显地在两个索引中时。我哪里做错了?在
pd.merge(df1, df2, on=df.index, how = "outer")
你可以试试:
对于您的任务,
pd.concat
比合并更好。但是使用merge
可以将两个数据帧与列rs#
上的reset_index
合并:如果需要生成的dataframe具有可以使用的原始索引,那么
^{pr2}$set_index
:相关问题 更多 >
编程相关推荐