Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I have a dataframe:
col1 col2 col3 1 4 6 5 2 3 6 1 0
I want to turn it into nested list:
array([[1,5,6],[4,2,1],[6,3,0]])
How could i do that?
Wouldn't df.T.values work?
df.T.values
array([[1, 5, 6], [4, 2, 1], [6, 3, 0]], dtype=int64)
or df.T.values.tolist()
df.T.values.tolist()
[[1, 5, 6], [4, 2, 1], [6, 3, 0]]
Add a comment
try this:
df= pd.DataFrame([[1,4,6],[5,2,3],[6,1,0]]) df.T.values ### returns >> array([[1,5,6],[4,2,1],[6,3,0]])
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.