0

I am trying to fetch values of each row of pandas dataframe using below code.

points = [ makePoint(row) for row in df.iterrows() ]

here df has 4 column. each contains integer data.

while i try to print row, it returns follow,

1    3
2    3
3    4
4    5
Name: 0, dtype: int64

I just need

[3,3,4,5] 

and don't want index, name and dtype.

Code_Art
  • 111
  • 1
  • 1
  • 9

1 Answers1

0

Use tolist() if need convert Series to list and iterrows return tuples - index with Series, so add i for unpacking it:

points = [ makePoint(row).tolist() for i, row in df.iterrows() ]

Or list:

points = [ list(makePoint(row)) for i, row in df.iterrows() ]

Another solution:

points = df.apply(makePoint, axis=1).values.tolist()
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252