I'm trying to merge multiple .txt files in a directory specifically merging on one of the common column X
found in dataframes.
import pandas as pd
df1 = pd.DataFrame({'X': ['X0', 'X1', 'X2', 'X3'],
...: 'B': ['B0', 'B1', 'B2', 'B3'],
...: 'C': ['C0', 'C1', 'C2', 'C3'],
...: 'D': ['D0', 'D1', 'D2', 'D3']})
df2 = pd.DataFrame({'X': ['X0', 'X1', 'X2', 'X3'],
...: 'G': ['G0', 'G1', 'G2', 'G3'],
...: 'H': ['H0', 'H1', 'H2', 'H3'],
...: 'J': ['J0', 'J1', 'J2', 'J3']})
by following previous this post Pandas Merging 101 and this https://pandas.pydata.org/pandas-docs/stable/user_guide/merging.html
I tried
data = pd.DataFrame()
for file in glob.iglob(filepath + '/*.txt', recursive=True):
print(file)
df=pd.read_csv(file, sep ='\t',header=0, skiprows=0, skipfooter=0, na_values=(""," ","NA"))
data=pd.concat([data,df])
data_merge = pd.merge(data,on='X',how='inner')
but I got
TypeError: merge() missing 1 required positional argument: 'right'
How can I join two datafame by common X
column?
the expected output
Thanks.