You have a string column and you want to split it into two columns in pandas.
Let’s read a dataset to work with.
import pandas as pd url = 'https://raw.githubusercontent.com/bprasad26/lwd/master/data/clothing_store_sales.csv' df = pd.read_csv(url) df.head()
Now, let’s say you want to split the Method of Payment column into two columns. You want to split the column on white space.
df[['M1','M2']] = df['Method of Payment'].str.split(' ', 1, expand=True)