I want to split the Pandas Series tuple on the fly in to multiple columns. Generate dummy data using code below:
df = pd.DataFrame(data={'a':[1, 2, 3, 4, 5, 6]})
df['b'] = pd.Series([(np.nan, 1), ('AB', 10), ('CD', 1), (3, 1), (4, 1), ('NA', 1)]).str[0]
df['c'] = pd.Series([(np.nan, 1), ('AB', 10), ('CD', 1), (3, 1), (4, 1), ('NA', 1)]).str[1]
How can I create column b and c in 1 line of code?
I've tried below code but it doesn't split as per the requirement.
df[['b', 'c']] = pd.Series([(np.nan, 1), ('AB', 10), ('CD', 1), (3, 1), (4, 1), ('NA', 1)]).str[0:2]