Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

pandas get tuples from dataframe

# adapted from Stack Overflow user answer in the source link
import pandas as pd
df = pd.DataFrame({"A" : [1, 1, 2, 2], "B" : [3, 4, 3, 4]})
tuples = [tuple(x) for x in df.to_numpy()]
tuples
>>> [(1, 3), (1, 4), (2, 3), (2, 4)]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #pandas #tuples #dataframe
ADD COMMENT
Topic
Name
7+5 =