Answer the question
In order to leave comments, you need to log in
How to loop through the first 10 rows in a DataFrame and increase the value in them by 1?
Is it possible to change the value of fields in a loop in Pandas?
Answer the question
In order to leave comments, you need to log in
"Is it possible in Pandas to change the value of fields in a loop?" - can. But in the question that stands in the title - this is not necessary.
I'm too lazy to fill a large DataFrame, so here's an abbreviated example. There are 10 rows in the dataframe, we change the first column in the first five rows.
print (df)
df.A.loc[:4]=df.A.loc[:4]+1
print (df)
. A B
0 1 2
1 2 4
2 3 6
3 4 8
4 5 0
5 1 2
6 2 4
7 3 6
8 4 8
9 5 0
. A B
0 2 2
1 3 4
2 4 6
3 5 8
4 6 0
5 1 2
6 2 4
7 3 6
8 4 8
9 5 0
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question