I have foll. dataframes (df_A and df_B):
df_A
Col_A Col_B
23 34
12 18
df_B
23 12
45 10
I want to merge them based on Col_A in df_A and 1st column in df_B. Note that df_B does not have any header row. How do I do this? A simple merge would have been:
df_A.merge(df_B, on='Col_A')
However that does not work in this case becuase df_B does not have Col_A as column.
--EDIT based on @EdChum's suggestion:
TO CLARIFY: I want to merge two dataframes. One has a header, and the other one does not. How do i specify the join column on a dataframe that does not have a header? Can I specify it by location/index?
df_B.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 1 entries, 0 to 0
Data columns (total 2 columns):
23 1 non-null int64
12 1 non-null int64
dtypes: int64(2)
memory usage: 24.0 bytes
df_B.columns.tolist()
['23', '12']
df_A.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 2 entries, 0 to 1
Data columns (total 2 columns):
Col_A 2 non-null int64
Col_B 2 non-null int64
dtypes: int64(2)
memory usage: 48.0 bytes
df_A.columns.tolist()
['Col_A', 'Col_B']
df_A.info()anddf_B.info()and also the output fromdf_A.columns.tolist()and the same fordf_Bthey will have columns despite what you thinkdf_A.merge(df_B, left_on='Col_A', right_on='23')df_B.info(), what doesdf_B.columns.tolist()showdf_Bto get what you want