Last active
June 8, 2018 15:41
-
-
Save Ruhshan/4196374f0ba7932aac09653018ee5a4f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I have a dataframe like this: | |
name vals | |
0 foo X | |
1 foo Y | |
2 foo Z | |
3 bar Y | |
4 bar Z | |
5 bar Q | |
How can I transform it to like this: | |
Q X Y Z | |
name | |
foo 0 1 1 1 | |
bar 1 0 1 1 | |
---------------------------------------------- | |
Code for first df: | |
df = pd.DataFrame({"name": ["foo", "foo", "foo", | |
"bar", "bar", "bar"], | |
"vals": ["X", "Y", "Z", | |
"Y", "Z", "Q"], | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment