My question is more about the methodology/syntax described into a previous post which addresses different approaches to meet the same objective of splitting string values into lists and assigning each list item to a new column. Here's the post: Pandas DataFrame, how do i split a column into two
df:
GDP
Date
Mar 31, 2017 19.03 trillion
Dec 31, 2016 18.87 trillion
script 1 + ouput:
>>> df['GDP'], df['Units'] = df['GDP'].str.split(' ', 1).str
>>> print(df)
GDP Units
Date
Mar 31, 2017 19.03 trillion
Dec 31, 2016 18.87 trillion
script 2 + output:
>>> df[['GDP', 'Units']] = df['GDP'].str.split(' ', 1, expand=True)
>>> print(df)
GDP Units
Date
Mar 31, 2017 19.03 trillion
Dec 31, 2016 18.87 trillion
script 3 + output:
>>> df['GDP'], df['Units'] = df['GDP'].str.split(' ', 1, expand=True)
>>> print(df)
GDP Units
Date
Mar 31, 2017 0 1
Dec 31, 2016 0 1
Can anyone explain what is going on? Why does script 3 produce these values in the output?