Last active
September 21, 2020 02:58
-
-
Save YiLi225/035c7ef0220afa674a2280cc03ad5871 to your computer and use it in GitHub Desktop.
This file contains 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
## Parse tuples of values into their own columns | |
### Step1: Convert each element to their own series | |
df_ = df["Nums"].apply(pd.Series) | |
Out[39]: | |
0 1 | |
index0 976 660 | |
index1 984 360 | |
index2 246 127 | |
index3 252 345 | |
index4 1419 1373 | |
index5 103 515 | |
### Step2: Join back to the original df | |
pd.merge(df, df_, left_index = True, right_index = True) | |
Out[40]: | |
Food Nums 0 1 | |
index0 Cows' milk, whole (976, 660) 976 660 | |
index1 skim (984, 360) 984 360 | |
index2 Buttermilk, cultured (246, 127) 246 127 | |
index3 Evaporated, undiluted (252, 345) 252 345 | |
index4 Fortified milk (1419, 1373) 1419 1373 | |
index5 Powdered milk, whole (103, 515) 103 515 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment