I have 2 columns in pandas, with data that looks like this.
code fx category
AXD AXDG.R cat1
AXF AXDG_e.FE cat1
333 333.R cat1
....
There are other categories but I am only interested in cat1.
I want to combine everything from the code column, and everything after the . in the fx column and replace the code column with the new combination without affecting the other rows.
code fx category
AXD.R AXDG.R cat1
AXF.FE AXDG_e.FE cat1
333.R 333.R cat1
.....
Here is my code, I think I have to use regex but I'm not sure how to combine it in this way.
df.loc[df['category']== 'cat1', 'code'] = df[df['category'] == 'cat1']['code'].str.replace(r'[a-z](?=\.)', '', regex=True).str.replace(r'_?(?=\.)','', regex=True).str.replace(r'G(?=\.)', '', regex=True)
I'm not sure how to select the second column also. Any help would be greatly appreciated.