How to plot a chart with text in the dataframes columns?

Hello!

I have a df that looks like this:

df

my goal is to make a line chart that sums up the codes for each month and, after this, add a dropdown to be able to filter between ‘type’, group’ and ‘Spec.’

If I didn’t want the dropdown filter, I could achieve this with

`df.groupby('month')['code'].count().reset_index()`

Since I need the filters, the ideal is to be able to do this sum in the graph code in plotly, so I don’t lose the ‘type’, group’ and ‘Spec.’ columns.

I tryed this code:

`line_fig1 = px.line(data_frame = df,
    x= 'month',
    y='code',
    labels={'month':'','code':''},
    title='',
    width=450,
    height=250,
    template='plotly_white',
    color_discrete_sequence= ["rgb(1, 27, 105)"],
    markers=True,
    text='code'
    )`

and this was the result:

chart

I also tryed something like

`line_fig1 = px.line(data_frame = df,
    x= 'month',
    y='code'.count()`

or even tryed to add a column with a number one, so the chart could aggregate

`df['assign_value'] = 1 

line_fig1 = px.line(data_frame = df,
    x= 'month',
    y='assign_value'`

But this also don’t work. This is the graph for this last code.

chart2

and yes, the type of the assign_value is int

Any help here?

HI @tex.y welcome to the forums.

Check the dtype of the column ‘month’. Is it datetime?

Hello!

No, it wasn’t

I tried to make this change now but it’s still generating the same chart as the image I showed above

df.groupby(['month','group','type','Spec'])['code'].count().reset_index()

or filter before count