I have a dataframe
tdf. It has several columns, three of which are X,Y,Z.
I would like to gather each row, and pass the values of X,Y,Z to a function as a single tuple.
At first I tried this:
def format_tuple(x):
print(x)
return x
tmdf = tdf[['X', 'Y', 'Z']].applymap(format_tuple)
This code however treats each column 'X', 'Y', 'Z' individually as seen in the print(x)
prints each columns' value individually, not as three columns converted to a single row tuple
.
Then I thought, turn the values into a tuple
like this but it doesn't work:
tmdf = tdf[['X', 'Y', 'Z']].apply(tuple, axis=1).applymap(format_tuple)