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.
Asked
Active
Viewed 1,095 times
0
-
Does this answer your question? [How to merge lists into a list of tuples?](https://stackoverflow.com/questions/2407398/how-to-merge-lists-into-a-list-of-tuples) – Karl Jun 06 '20 at 14:56
-
Besides the solutions in Karl's comment you might want to take a look at enumerate: https://docs.python.org/3.7/library/functions.html#enumerate It provides a way to create a temporary id for an iterable. – Adrian Klaver Jun 06 '20 at 15:38
-
I have tried both ways but seems not working and cannot Print the new value. Is it possible you could help list the code. Great Appreciate for your help! @KarlWilhelm – Ng Ct Jun 06 '20 at 16:51
-
You're going to have to show a lot more code if you expect to get a high quality answer. You should try to make a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) – bfris Jun 06 '20 at 17:37
2 Answers
0
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

Tiffoox
- 16
- 3
-
`table1 = pd.DataFrame(table1) #Table with the first three columns table2= pd.Series(Prediction_df) #Table with Price Prediction table1["Price Prediction"] = table2` However, it pop up TypeError: 'int' object is not iterable Do you know how it can be fixed? – Ng Ct Jun 06 '20 at 16:46
-
It should work .. You may have a problem with column names or column types. Can you give additional information ? – Tiffoox Jun 06 '20 at 17:06
0
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)

Ng Ct
- 51
- 7