Returning One-item Series As A Tuple In Pandas
I have a dataframe that, given my input set, only returns one item from an operation, and I need to dump that item as a single tuple. Here's the df (code to generate below): df
Solution 1:
You're almost there! The following will give you what you want:
tuple(df.loc[[df['number'].idxmax()], 'number'].reset_index().values[0])
or, if you wanted to use arrays:
arr = df.reset_index().values
tuple(arr[arr.argmax(axis=0)[2], [0, 2]])
p.s. there's a typo in your df creation code, missiong '
before orangutans
Post a Comment for "Returning One-item Series As A Tuple In Pandas"