Parag
Parag

Reputation: 345

pandas dataframe replace % character

I am having following dataframe e.g.

    symbol  dayHigh dayLow  lastPrice   yearHigh    yearLow previousClose   change  pChange
82  M%M 557 546.6   556 740 502.55  546.6   9.40    1.72
83  M%MFIN  344.4   333.2   343.1   461.45  284.85  332 11.10   3.34

I want to replace '%' character starting with 'M%' as 'M%26'

I tried following

nifty1['symbol']= np.where(nifty1['symbol'] == 'M%%', 'M%26', nifty1['symbol']) 
nifty1['symbol']= np.where(nifty1['symbol'] == u'M%%', u'M%26', nifty1['symbol'])

but it's not successful.

Upvotes: 0

Views: 59

Answers (1)

Lav
Lav

Reputation: 49

In pandas majority of string manipulation operations can be found under 'str'. See solution below :

df['symbol'] = df['symbol'].str.replace('M%', 'M%26', regex=False)

Edited to match your requirement.

Upvotes: 2

Related Questions