繁体   English   中英

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

[英](Python) How to Copy and Paste a column to another table?

我有 2 个表,是否可以在不按 ID 合并的情况下合并 2 个表? 因为这2个表的ID不一致。 这 2 个表的行数相同。 非常感谢,如果有人可以提供帮助。

在此处输入图像描述

在此处输入图像描述

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

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

我相信有更好的方法来实现。 但是,我通过这个解决了问题

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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM