((Python)如何将列复制并粘贴到另一个表中?

问题描述 投票:0回答:2

我有2个表,是否可以合并2个表而不通过ID合并?因为这两个表的ID不一致。这2个表的行数相同。非常感谢任何人的帮助。

enter image description here

enter image description here

python python-3.x
2个回答
0
投票

我不确定是否能回答您的问题,但是请尝试以下代码:

import pandas as pd

table1 = pd.DataFrame(table1) #Table with the first three columns
table2= pd.Series(table2) #Table with Price Prediction
table1["Price Prediction"] = table2


0
投票

我相信有更好的方法可以实现。但是,我通过此方法解决了问题

df_out = Table1.reset_index()

Prediction_df = pd.DataFrame(predictions)
Prediction_df = Prediction_df.rename(columns={'XXX': 'Prediction'})
Prediction_df['prediction'] = Prediction_df.reset_index()['Prediction']
df_out1 = pd.merge(df_out,Prediction_df[['prediction']],how = 'left',left_index = True, right_index = True)
© www.soinside.com 2019 - 2024. All rights reserved.