2024-09-28 03:15:50 发布
网友
在pandas中我有两个不同的数据帧。示例:
df1=a b df2= c 0 1 1 1 2 2 2 3 3
我想把它们合并在一起
我尝试使用df1['c'] = df2['c'],但是我得到了一个带有copywarnings的设置
df1['c'] = df2['c']
为了合并两个数据帧,可以使用这两个示例。两者都返回相同的目标。在
使用merge加上指示它使用索引的附加参数
merge
试试这个:
response = pandas.merge(df1, df2, left_index=True, right_index=True) In [2]: response Out[2]: b c 0 1 1 1 2 2 2 3 3
或者您可以使用join。以防你的daraframes有不同的索引。在
join
DataFrame.join is a convenient method for combining the columns of two potentially differently-indexed DataFrames into a single result DataFrame.
下面是一个基本示例:
为了合并两个数据帧,可以使用这两个示例。两者都返回相同的目标。在
使用
merge
加上指示它使用索引的附加参数试试这个:
或者您可以使用
join
。以防你的daraframes有不同的索引。在下面是一个基本示例:
^{pr2}$相关问题 更多 >
编程相关推荐