This is my code for dataframing for both df1 and df2. I'm trying to merge these df1 and df2.
import pandas as pd
df1 = pd.read_table("mass2.txt")
df1.columns =['ID']
print(df1)
df2 = pd.read_table("combined.txt",sep=",")
df2.columns =['Teff','ID']
print(df2)
columns_titles = ["ID","Teff"]
df3=df2.reindex(columns=columns_titles)
print(df3)
df4 = df1.merge(df3, on='ID', how='left')
print(df4)´´´
I need to merge df2 and df1. There are similar IDs in df1 and
df2 but it's not giving me the respective Teff.
I'm getting an output like this:
ID Teff
0 J22154748 + 4954052 NaN
1 J22154748 + 4954052 NaN
2 J22152631 + 4958343 NaN
3 J22154748 + 4954052 NaN
4 J22154748 + 4954052 NaN
... ... ...
1122 AP17515104-3446100 NaN
1123 AP17515104-3446100 NaN
1124 J05062845 + 4112062 NaN
1125 J16142485-3141000 NaN
1126 J16142485-3141000 NaN´´´
So, there is nothing in Teff column for similar IDs I have in df1 and df2.