Kurosaki Kurosaki - 1 month ago 6
Python Question

How to adjust the specific data in rows or in columns?

It's a little bit weird that I used nested loop, but it failed, it shows 'numpy.ndarray' object is not callable. So, does it have a better way to adjust each data in column data or row?
For example:

df

a b c d
A 1 3 4 7
B 2 3 5 1
C 1 5 6 8
D 2 1 7 9


How can I add a number, such as

num = 1


And I wanna add num to each data in column 'c', like this:

a b c d
A 1 3 5 7
B 2 3 6 1
C 1 5 7 8
D 2 1 8 9


Or I wanna add num to each data in row 'C', like this:

a b c d
A 1 3 4 7
B 2 3 5 1
C 2 6 8 9
D 2 1 7 9


How can this work? Use nested loop like

for row in df.index:
for row in df['c']


Or

for row in df.index:
df.ix[row, 'c'] = df.ix[row, 'c'] + num


Can somebody help me check it out? Thanks!!!

Answer
df.loc[:, 'c'] += 1
df.loc['C', :] += 1