I have two dataframes from a SQL connection which I'm trying to merge but I kept getting the same error: # Check for duplicates KeyError: 'Transaction'. I'm using drop duplicates and str.strip in order to avoid duplicates.
First dataframe (df): it came from a SQL connection, I have just one column named "Transaction" it's only text (str). I applied this in order to avoid spaces and duplicates:
df['Transaction'] = df['Transaction'].str.strip ()
df = df.drop_duplicates()
Second dataframe (df_2): it came from a diferent connection to SQL than df, I just have one column but with text an numbers. I also applied:
df_2['desc_p'] = df_2['desc_p'].str.strip ()
df_2 = df_2.drop_duplicates()
when I'm traying to merge I tried two different things but doesn't work. I checked on excel and I don't have any duplicate value, also the data match, this being said, the data I have on df is in df_2.
df = pd.merge (df.astype(str), df_2.astype(str), how='left', on='Transaction')
df = df.merge(df_2, how='left', on = 'Transaction')
Please help me :( I'm getting mad with this, I'm kinda new in python and I'm not seeing anything because this is not working.