我不知道这个任务是否可以用牵牛星或熊猫来完成,但我正在寻找文档来更改我的图形的date语言。
下面是我的代码:
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",
)输出:

发布于 2020-11-19 11:53:36
目前还没有很好的文档,但在How to set locale in Altair?中有一些相关的信息。
您可以为图表设置西班牙语时间格式区域设置,如下所示:
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
)

https://stackoverflow.com/questions/64904989
复制相似问题