I had the code pattern which provides the output in pandas.series type.From that i need to remove the value counts column without changing the pattern of table.
the code i have tried is,
import pandas as pd
df = pd.DataFrame({'A':['a','b'],'C':['1','2'],
'B':[[['A1', 'A2']],[['A1', 'A2', 'A3']]]})
df = df['B'].apply(lambda x: pd.Series(x[0])).stack().reset_index(level=1, drop=True).to_frame('B').join(df[['A','C']], how='left')
print(df.groupby(['A', 'C']).value_counts().sort_index())
the output i got is
A C B
a 1 A1 1
A2 1
b 2 A1 1
A2 1
A3 1
dtype: int64
the expected result is
A C B
a 1 A1
A2
b 2 A1
A2
A3
thanks in advance
CodePudding user response: