简体   繁体   中英

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

I have 2 tables, is it possible I could merge 2 tables without merging by ID? Because the ID of these 2 tables are not consistent. These 2 Tables have the same amount of row. Great thanks if anyone could help.

在此处输入图像描述

在此处输入图像描述

I'm not sure if it answers your question but try this code:

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

I believe there are better ways to achieve. However, I solve the problem by this

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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