By using the below code, I have the following output. But I need to create a plot from it (ggplot). My understanding is that I need to transform the DS to a DF.
Can someone help me on how to make my current dataset A,to look like a dataframe B as per below?
A) Current
ds_perg1_2_merged = df_perg1_2.groupby(['DescricaoProblema'])['strRazaoSocial'].apply(lambda x: x.value_counts().head(3))
DescricaoProblema
Cobrança indevida. CAIXA ECONOMICA FEDERAL 66
CAIXA SEGUROS S.A 45
BANCO BMG S.A. 38
Cobrança indevida/abusiva CLARO S/A 50
TIM CELULAR S/A 47
COMPANHIA PIRATININGA DE FORÇA E LUZ 34
Produto com vício VIA VAREJO S/A 46
SAMSUNG ELETRONICA DA AMAZONIA LTDA 27
WHIRLPOOL S/A 23
ds_perg1_2_merged.info()
<class 'pandas.core.series.Series'>
MultiIndex: 9 entries, ('Cobrança indevida.', 'CAIXA ECONOMICA FEDERAL') to ('Produto com vício', 'ELECTROLUX DO BRASIL S/A')
Series name: strRazaoSocial
Non-Null Count Dtype
-------------- -----
9 non-null int64
dtypes: int64(1)
memory usage: 568.0+ bytes
B) Need to be:
DescricaoProblema strRazaoSocial amount
Cobrança indevida. CAIXA ECONOMICA FEDERAL 66
CAIXA SEGUROS S.A 45
BANCO BMG S.A. 38
Cobrança indevida/abusiva CLARO S/A 50
TIM CELULAR S/A 47
COMPANHIA PIRATININGA DE FORÇA E LUZ 34
Produto com vício VIA VAREJO S/A 46
SAMSUNG ELETRONICA DA AMAZONIA LTDA 27
WHIRLPOOL S/A 23
EDIT: Ok, so I resolved half of the issue using ds_perg1_2_merged.to_frame()
...But for the third column of values I still need a separate column name. Not sure if I'm in the right path tho.