0

I have a Dataframe that has two columns as below:

col_a,col_b
10,32
23,43
32,64

I am trying to get the Dataframe converted to the below format:

[(10,32),(23,43),(32,64)]
scott martin
  • 1,253
  • 1
  • 14
  • 36
  • Possible duplicate of [Python: Create structured numpy structured array from two columns in a DataFrame](https://stackoverflow.com/questions/51279973/python-create-structured-numpy-structured-array-from-two-columns-in-a-dataframe) – Asmus Apr 26 '19 at 11:28

1 Answers1

1

Use list comprehension or map with convert lists to tuples:

L = [tuple(x) for x in df.values.tolist()]

L = list(map(tuple, df.values.tolist()))

Another solution with zip and transpose:

L = list(zip(*df.T.values.tolist()))

print (L)
[(10, 32), (23, 43), (32, 64)]
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252