I have a dataframe like this:
import pandas as pd
df1 = pd.DataFrame(
{'A': {0: '1', 1: '7', 2: '7', 3: '1', 4: '7', 5: '1'},
'B': {0: 'S', 1: 'S', 2: 'D', 3: 'D', 4: 'D', 5: 'S'}})
display(df1.head())
I want to convert above dataframe (dynamically) to this:
df2 = pd.DataFrame({
'A': {0: '1', 1: '7'},
'S': {0: 2, 1: 1},
'D': {0: 1, 1: 2},
})
display(df2.head())
I know how to use 'groupBy', but I don't know how to automatically convert fields into new columns.