Skip to main content
Active reading [<https://en.wiktionary.org/wiki/straightforward#Adjective>]. More representative link text.
Source Link
Peter Mortensen
  • 31.2k
  • 22
  • 111
  • 134

Probably the most elegant solution (but certainly not the most efficient):

for row in df.values:
    c2 = row[1]
    print(row)
    # ...

for c1, c2 in df.values:
    # ...

Note that:

  • the documentationthe documentation explicitly recommends to use .to_numpy() instead
  • the produced NumPy array will have a dtype that fits all columns, in the worst case object
  • there are good reasons not to use a loop in the first place

Still, I think this option should be included here, as a straight-forwardstraightforward solution to a (one should think) trivial problem.

Probably the most elegant solution (but certainly not the most efficient):

for row in df.values:
    c2 = row[1]
    print(row)
    # ...

for c1, c2 in df.values:
    # ...

Note that:

  • the documentation explicitly recommends to use .to_numpy() instead
  • the produced NumPy array will have a dtype that fits all columns, in the worst case object
  • there are good reasons not to use a loop in the first place

Still, I think this option should be included here, as a straight-forward solution to a (one should think) trivial problem.

Probably the most elegant solution (but certainly not the most efficient):

for row in df.values:
    c2 = row[1]
    print(row)
    # ...

for c1, c2 in df.values:
    # ...

Note that:

  • the documentation explicitly recommends to use .to_numpy() instead
  • the produced NumPy array will have a dtype that fits all columns, in the worst case object
  • there are good reasons not to use a loop in the first place

Still, I think this option should be included here, as a straightforward solution to a (one should think) trivial problem.

corrected hint on mixed types
Source Link

Probably the most elegant solution (but certainly not the most efficient):

for row in df.values:
    c2 = row[1]
    print(row)
    # ...

for c1, c2 in df.values:
    # ...

Note that:

  • the documentation explicitly recommends to use .to_numpy() instead
  • this might bethe produced NumPy array will have a bad idea fordtype that fits all columns, in the worst case DataFrameobjects with mixed type columns
  • there are good reasons not to use a loop in the first place

Still, I think this option should be included here, as a straight-forward solution to a (one should think) trivial problem.

Probably the most elegant solution (but certainly not the most efficient):

for row in df.values:
    c2 = row[1]
    print(row)
    # ...

for c1, c2 in df.values:
    # ...

Note that:

  • the documentation explicitly recommends to use .to_numpy() instead
  • this might be a bad idea for DataFrames with mixed type columns
  • there are good reasons not to use a loop in the first place

Still, I think this option should be included here, as a straight-forward solution to a (one should think) trivial problem.

Probably the most elegant solution (but certainly not the most efficient):

for row in df.values:
    c2 = row[1]
    print(row)
    # ...

for c1, c2 in df.values:
    # ...

Note that:

  • the documentation explicitly recommends to use .to_numpy() instead
  • the produced NumPy array will have a dtype that fits all columns, in the worst case object
  • there are good reasons not to use a loop in the first place

Still, I think this option should be included here, as a straight-forward solution to a (one should think) trivial problem.

Source Link

Probably the most elegant solution (but certainly not the most efficient):

for row in df.values:
    c2 = row[1]
    print(row)
    # ...

for c1, c2 in df.values:
    # ...

Note that:

  • the documentation explicitly recommends to use .to_numpy() instead
  • this might be a bad idea for DataFrames with mixed type columns
  • there are good reasons not to use a loop in the first place

Still, I think this option should be included here, as a straight-forward solution to a (one should think) trivial problem.