0

The grouped data looks like

The Grouped Data looks like

My approach yields to

enter image description here

I'd want a result like

enter image description here

Is there an easy way to achieve that?

2
  • 1
    Please provide data. Don't share the data as a pic. Commented Mar 10, 2022 at 11:25
  • 1
    Group again by MAPPING, then plot or use seaborn or pivot MAPPING into distinct columns. Commented Mar 10, 2022 at 13:17

1 Answer 1

1

As the test DataFrame I used:

         MAPPING CREATED_DTM  counts
0  Beschaedigung  2020-04-30   22738
1  Beschaedigung  2020-05-31   21523
2  Beschaedigung  2020-06-30   18516
3  Beschaedigung  2020-07-31   21436
4  Beschaedigung  2020-08-31   22325
5        Verlust  2020-04-30   20000
6        Verlust  2020-05-31   19500
7        Verlust  2020-06-30   22400
8        Verlust  2020-07-31   19100
9        Verlust  2020-08-31   21100

(CREATED_DTM column of datetime64[ns] type).

An elegant solution to create the plot you want, is to use seaborn.

Start from necessary imports:

import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib.dates as md

Then, run:

sns.lineplot(data=reaktiv_mapping, x='CREATED_DTM', y='counts', hue='MAPPING')
ax = plt.gca()
x = ax.xaxis
x.set_major_locator(md.MonthLocator())
x.set_major_formatter(md.DateFormatter('%Y-%m'))
plt.xticks(rotation = 45)
ax.legend(loc='upper left', bbox_to_anchor=(1.05, 1.0));

For the above source data, I got the following plot:

enter image description here

To get the grid, like in your expected picture, you can start with:

sns.set_style('darkgrid')
Sign up to request clarification or add additional context in comments.

1 Comment

you are an angel, thank you very much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.