Reputation: 1066
I have a column which goes in a pattern like this:
RS
RS
GF
NB
BP
TO
RS
GF
NB
BP
TO
...
and I want to convert the RSs into RS1 and RS2. The first one should be RS1 and the second one should be RS2. And the one in the middle needs to be RS1. And this pattern repeats on. How would I do this in pandas?
Upvotes: 0
Views: 16
Reputation: 5362
Assuming you have a DataFrame
column which repeats every 11 rows
df['col']
# col
#0 RS
#1 RS
#2 GF
#3 NB
#4 BP
#5 TO
#6 RS
#7 GF
#8 NB
#9 BP
#10 TO
#11 RS
#12 RS
# ...
then you can use simple slicing
df.ix[ df.index[0::11],'col'] = 'RS1'
df.ix[ df.index[1::11],'col'] = 'RS2'
df.ix[ df.index[6::11],'col'] = 'RS1'
Upvotes: 1