I've seen other posts about this but I'm running into an issue trying to follow the solutions. I am trying to split a column of scores (as strings) that are listed like this:
1-0
2-3
0-3
...
The code I'm trying to use:
df[['Home G', 'Away G']] = df['Score'].str.split('-', expand=True)
Error I am getting:
ValueError: Columns must be same length as key
Every game has a score though so the column length should match up? One thought I had is the 0's are giving some weird none values or something like that?
'-'character? Try the solutions in this post.df[~df['Score'].str.contains('-')]is an emptyDataFramedf = pd.DataFrame({'Score': ['1-0', '2-3', '0-3', np.NaN, '32', 3]})and thendf.Score.str.split('-', expand=True)(which returns 2 columns). But having multiple "-" characters could be problematic if you don't specify how many splits to make.