0

#Following is a dataframe i created

dict1 = {'Store': 'A','B','A','C','D','A','D','A','C','B'],'Location':'Mumbai','Pune','Hyderabad','Mumbai','Pune','Delhi','Hyderabad','Pune','Mumbai','Pune'],'Sales':40000,45000,50000,90000,89000,87000,85000,78000,89000,70000]}
data1 = pn.DataFrame(dict1)

#want to change the name of the stores:

data1.loc[(data1.Store == 'A'), 'Store'] = 'Store_A'
data1.loc[(data1.Store == 'B'), 'Store'] = 'Store_B'
data1.loc[(data1.Store == 'C'), 'Store'] = 'Store_C'
data1.loc[(data1.Store == 'D'), 'Store'] = 'Store_D'

#How do to this in one line instead of 4 lines

1 Answers1

1

If you just want to concatenate a string Store_ ahead of all rows in a given column, then you can try:

data1['Store'] = 'Store_' + data1['Store']