Splitting A List Of Tuples In A Pandas Dataframe Column
I have a dataframe where each element is a lists of tuples. import pandas as pd data={'A':[[('potatoes',9),('cabbages',7),('carrots',5),('onions',2)]], 'B':[[('cabbages',5),
Solution 1:
See below,
ww3 = pd.DataFrame()
l = len(ww.columns)
for i in range(l):
ww3[i] = ww[i].apply(lambda x: x[0])
ww3[i+l] = ww[i].apply(lambda x: x[1])
print (ww3)
0 4 1 5 2 6 3 7
A potatoes 9 cabbages 7 carrots 5 onions 2
B cabbages 5 apples 1 plums 9 peaches 6
Post a Comment for "Splitting A List Of Tuples In A Pandas Dataframe Column"