I have a panda data frame. One of the columns contains a list. I want that column to be a single string.
For example my list ['one','two','three'] should simply be 'one, two, three'
df['col'] = df['col'].astype(str).apply(lambda x: ', '.join(df['col'].astype(str)))
gives me ['one, two, three],['four','five','six'] where the second list is from the next row. Needless to say with millions of rows this concatenation across rows is not only incorrect, it kills my memory.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…