ckb
ckb

Reputation: 21

how to convert certain values for one of the column of dataframe?

Say there is a data frame df

A     B

0   Aus Brazilian Restaurant

1   Aus Gym

2   Aus Zoo

3   Aus Restaurant Thai

4   Aus Australian restaurant

Need to convert it to

A     B

0   Aus Restaurant

1   Aus Gym

2   Aus Zoo

3   Aus Restaurant

4   Aus Restaurant

code to create dataframe:

temp = {'A':5*['Aus'],'B':['Brazilian Restaurant','Gym','Zoo','Restaurant Thai','Australian restaurant']
     }

temp

df = pd.DataFrame(temp)

df

This is the code in Ipython

Upvotes: 1

Views: 12

Answers (1)

ckb
ckb

Reputation: 21

I have found a solution. Posting here, in case it is of use for someone.

for i in range(df.shape[0]):
if ('Restaurant' in df.loc[i,'B'] or 'restaurant' in df.loc[i,'B']):
    df.loc[i,'B']='Restaurant'

df

Upvotes: 1

Related Questions