Skip to main content
Fixed the weird syntax highlighting (as a result, the diff looks more extensive than it really is - use view "Side-by-side Markdown" to compare), etc.
Source Link
Peter Mortensen
  • 31.2k
  • 22
  • 111
  • 134

I recommend using df.at[row, column] (source) for iterate all pandas cells.

For example  :

for row in range(len(df)):
  print(df.at[row, 'c1'], df.at[row, 'c2'])

The output will be:

10 100
11 110
12 120
10 100
11 110
12 120

Bonus

You can also modify the value of cells with df.at[row, column] = newValue.

for row in range(len(df)):
  df.at[row, 'c1'] = 'data-' + str(df.at[row, 'c1'])
  print(df.at[row, 'c1'], df.at[row, 'c2']) 

The output will be:

data-10 100
data-11 110
data-12 120
data-10 100
data-11 110
data-12 120

I recommend using df.at[row, column] (source) for iterate all pandas cells.

For example  :

for row in range(len(df)):
  print(df.at[row, 'c1'], df.at[row, 'c2'])

The output will be:

10 100
11 110
12 120

Bonus

You can also modify the value of cells with df.at[row, column] = newValue.

for row in range(len(df)):
  df.at[row, 'c1'] = 'data-' + str(df.at[row, 'c1'])
  print(df.at[row, 'c1'], df.at[row, 'c2']) 

The output will be:

data-10 100
data-11 110
data-12 120

I recommend using df.at[row, column] (source) for iterate all pandas cells.

For example:

for row in range(len(df)):
  print(df.at[row, 'c1'], df.at[row, 'c2'])

The output will be:

10 100
11 110
12 120

Bonus

You can also modify the value of cells with df.at[row, column] = newValue.

for row in range(len(df)):
  df.at[row, 'c1'] = 'data-' + str(df.at[row, 'c1'])
  print(df.at[row, 'c1'], df.at[row, 'c2']) 

The output will be:

data-10 100
data-11 110
data-12 120
added 34 characters in body
Source Link
Jordy
  • 2.1k
  • 3
  • 13
  • 40

I recommend using df.at[row, column] (source) for iterate all pandas cells. 

For example :

for row in range(len(df)):
  print(df.at[row, 'c1'], df.at[row, 'c2'])

The output will be:

10 100
11 110
12 120

Bonus

You can also modify the value of cellcells with df.at[row, column] = newValue.

for row in range(len(df)):
  df.at[row, 'c1'] = 'data-' + str(df.at[row, 'c1'])
  print(df.at[row, 'c1'], df.at[row, 'c2']) 

The output will be:

data-10 100
data-11 110
data-12 120

I recommend using df.at[row, column] (source). For example :

for row in range(len(df)):
  print(df.at[row, 'c1'], df.at[row, 'c2'])

The output will be:

10 100
11 110
12 120

Bonus

You can also modify the value of cell with df.at[row, column] = newValue.

for row in range(len(df)):
  df.at[row, 'c1'] = 'data-' + str(df.at[row, 'c1'])
  print(df.at[row, 'c1'], df.at[row, 'c2']) 

The output will be:

data-10 100
data-11 110
data-12 120

I recommend using df.at[row, column] (source) for iterate all pandas cells. 

For example :

for row in range(len(df)):
  print(df.at[row, 'c1'], df.at[row, 'c2'])

The output will be:

10 100
11 110
12 120

Bonus

You can also modify the value of cells with df.at[row, column] = newValue.

for row in range(len(df)):
  df.at[row, 'c1'] = 'data-' + str(df.at[row, 'c1'])
  print(df.at[row, 'c1'], df.at[row, 'c2']) 

The output will be:

data-10 100
data-11 110
data-12 120
edited body
Source Link
Jordy
  • 2.1k
  • 3
  • 13
  • 40

I recommend using df.at[row, column] (source). For example :

for row in range(len(df)):
  print(df.at[row, 'c1'], df.at[row, 'c2'])

The output will be:

10 100
11 110
12 120

Bonus

You can also updatemodify the value of cell with df.at[row, column] = newValue.

for row in range(len(df)):
  df.at[row, 'c1'] = 'data-' + str(df.at[row, 'c1'])
  print(df.at[row, 'c1'], df.at[row, 'c2']) 

The output will be:

data-10 100
data-11 110
data-12 120

I recommend using df.at[row, column] (source). For example :

for row in range(len(df)):
  print(df.at[row, 'c1'], df.at[row, 'c2'])

The output will be:

10 100
11 110
12 120

Bonus

You can also update the value of cell with df.at[row, column] = newValue.

for row in range(len(df)):
  df.at[row, 'c1'] = 'data-' + str(df.at[row, 'c1'])
  print(df.at[row, 'c1'], df.at[row, 'c2']) 

The output will be:

data-10 100
data-11 110
data-12 120

I recommend using df.at[row, column] (source). For example :

for row in range(len(df)):
  print(df.at[row, 'c1'], df.at[row, 'c2'])

The output will be:

10 100
11 110
12 120

Bonus

You can also modify the value of cell with df.at[row, column] = newValue.

for row in range(len(df)):
  df.at[row, 'c1'] = 'data-' + str(df.at[row, 'c1'])
  print(df.at[row, 'c1'], df.at[row, 'c2']) 

The output will be:

data-10 100
data-11 110
data-12 120
add update data feature
Source Link
Jordy
  • 2.1k
  • 3
  • 13
  • 40
Loading
Source Link
Jordy
  • 2.1k
  • 3
  • 13
  • 40
Loading