Ist es möglich, die Datumssprache in Altair oder Pandas zu ändern?
Nov 19 2020
Ich habe keine Ahnung, ob diese Aufgabe von Altair oder Pandas aus ausgeführt werden kann, aber ich suche nach der Dokumentation, um die date
Sprache meines Diagramms zu ändern .
Hier ist mein Code:
import pandas as pd
import altair as alt
from datetime import datetime, timedelta
url = 'https://raw.githubusercontent.com/mariorz/covid19-mx-time-series/master/data/covid19_confirmed_mx.csv'
df = pd.read_csv(url, index_col=0)
#df = pd.read_csv(url)
df = df.loc['Colima','18-03-2020':'18-11-2020']
df = pd.DataFrame(df)
df.index = pd.to_datetime(df.index, format='%d-%m-%Y')
%run urban_theme.py
alt.Chart(df.reset_index()).mark_line().encode(
alt.X('index:T', title = " "),
alt.Y('Colima:Q', title = " "),
).properties(
title = "Casos acumulados",
)
Ausgabe:

Antworten
3 jakevdp Nov 19 2020 at 10:53
Es ist derzeit nicht gut dokumentiert, aber es gibt einige relevante Informationen unter So legen Sie das Gebietsschema in Altair fest. .
Sie können ein Gebietsschema für das spanische Zeitformat für Ihr Diagramm wie folgt festlegen:
import pandas as pd
import altair as alt
from datetime import datetime, timedelta
from urllib import request
import json
# fetch & enable a Spanish timeFormat locale.
with request.urlopen('https://raw.githubusercontent.com/d3/d3-time-format/master/locale/es-ES.json') as f:
es_time_format = json.load(f)
alt.renderers.set_embed_options(timeFormatLocale=es_time_format)
url = 'https://raw.githubusercontent.com/mariorz/covid19-mx-time-series/master/data/covid19_confirmed_mx.csv'
df = pd.read_csv(url, index_col=0)
#df = pd.read_csv(url)
df = df.loc['Colima','18-03-2020':'18-11-2020']
df = pd.DataFrame(df)
df.index = pd.to_datetime(df.index, format='%d-%m-%Y')
alt.Chart(df.reset_index()).mark_line().encode(
alt.X('index:T', title = " "),
alt.Y('Colima:Q', title = " "),
).properties(
title = "Casos acumulados",
width = 800
)
