Pandas: Convert lists within a single column to multiple columns
问题 I have a dataframe that includes columns with multiple attributes separated by commas: df = pd.DataFrame({'id': [1,2,3], 'labels' : ["a,b,c", "c,a", "d,a,b"]}) id labels 0 1 a,b,c 1 2 c,a 2 3 d,a,b (I know this isn't an ideal situation, but the data originates from an external source.) I want to turn the multi-attribute columns into multiple columns, one for each label, so that I can treat them as categorical variables. Desired output: id a b c d 0 1 True True True False 1 2 True False True