I need to map a column names in data frame using python, I have some different data set in my csv need to match (mapping) a columns to standard name like following .
set 1 set 2
userId :[(1,2,3)] customerId : [(1,2,3)] userName :[('sam','ram','mam')] customerName : [('raj','tej','tej')] contact : [('sam@gmail','ram@gmail','mam@gmail')] email : [('raj@gmail','tej@gmail','tej@gmail')]
I need like
pd[id]=pd[userId] or pd[customerId] pd[name]=pd[userName ] or pd[customerName]
I have tried or condition using pandas . its working but I needd some standard solution.
if 'Number' in df.columns:
df_new = df.rename(columns = {'Number': 'Id'})
if 'Address' in df.columns:
df_new = df.rename(columns = {'Address': 'address'})
try this: