issue with seaborn

Reto reto at labrat.space
Sat Feb 20 08:07:08 EST 2021


Don't have the original email, hence replying this way.

On Sat, Feb 20, 2021 at 12:13:30PM +0100, jak wrote:
> Il 20/02/2021 01:56, Dino ha scritto:
> >
> > trying to do some dayaviz with Italian Covid Open Data (
> > https://github.com/italia/covid19-opendata-vaccini/ )
> >
> > here's how I pull my data:
> > ____________________________
> > import sys
> > import urllib.request
> > import pandas as pd
> > import ssl
> > ssl._create_default_https_context = ssl._create_unverified_context
> >
> > URL = "https://github.com/italia/covid19-opendata-vaccini/blob/master/dati/somministrazioni-vaccini-latest.csv?raw=true"
> >
> >
> > with urllib.request.urlopen(URL) as url:
> >      df = pd.read_csv(url)
> > ____________________________
> >
> > One of my diagrams came out screwed up today, and I am having a hard
> > time understanding what went wrong:
> >
> > https://imgur.com/a/XTd4akn
> >
> > Any ideas?
> >
> > Thanks
>
>
> I don't think this is the cause of your problem and in addition I don't
> know about pandas. In any case you send pandas some records that contain
> the date in string format and this gives the alphabetic continuity but
> if the data contained time holes, these would not be represented in your
> graph. Maybe you should add an intermediate step and convert strings
> dates to datetime format before you create the chart (but perhaps pandas
> takes care of this. I don't know this).

Pretty much what he said...
Parse the dates. Oh and you generally don't need the dance with urllib, pandas
can do that for you.

```
data_url = r"https://github.com/italia/covid19-opendata-vaccini/blob/master/dati/somministrazioni-vaccini-latest.csv?raw=true"

df = pd.read_csv(data_url, parse_dates=True, index_col="data_somministrazione")

plt.figure(figsize=(15,10))
plt.xticks(rotation=70)
sns.lineplot(x=df.index, y="prima_dose", data=df, hue="nome_area", ci=None)
```

Yields: https://labrat.space/irc/3b0be1f11e6c687b/download%20(1).png

Cheers,
Reto


More information about the Python-list mailing list