I have the following DataFrame
, where Track ID
is the row index. How can I split the string in the stats
column into 5 columns of numb
If you have a sequence of tuples and not strings, and you want them as DataFrame columns, this is the simplest approach:
df = pd.concat([df['Track ID'],pd.DataFrame(df['stats'].values.tolist())], axis=1)
If it is actually strings, you can first convert it to lists like so, then apply the above operation:
dfpart = pd.DataFrame(df['stats'].apply(lambda x: x.strip('()').split(', ')).values.tolist()).astype(float)
df = pd.concat([df['Track ID'], dfpart], axis=1)