Mailing List Archive

Re: issue with seaborn
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).

cheers.
--
https://mail.python.org/mailman/listinfo/python-list
Re: issue with seaborn [ In reply to ]
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
--
https://mail.python.org/mailman/listinfo/python-list
Re: issue with seaborn [ In reply to ]
Dino wrote:

> 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?
>

I first downloaded a local copy of the .csv file
using ....

wget URL

Then the python code below following the plot parameters
shown in your imgur.com image which was executed
in a jupyter notebook ....

# it_covid.py -----------------------------------------------

import pandas as pd
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt

df = pd.read_csv( 'data/somministrazioni-vaccini-latest.csv' )

plt.figure( figsize = ( 20 , 10 ) )

plt.xticks( rotation = 70 )

sns.lineplot(
x = "data_somministrazione" ,
y = "prima_dose" ,
data = df ,
hue = "nome_area" ,
ci = None )


plt.show()

# -----------------------------------------------------------

The resulting plot doesn't seem to be cluttered
as the one that you posted ....

http://csphx.net/image/it_covid.png


--
Stanley C. Kitching
Human Being
Phoenix, Arizona

--
https://mail.python.org/mailman/listinfo/python-list