我正在使用 Jupyter 笔记本处理 COVID 数据,其中我用我的语言环境转换了日期格式,效果很好。我使用了以下代码,并且能够添加带有区域设置日期的列。
import locale
locale.setlocale(locale.LC_TIME, "ta_TA.utf8")
df_state = res[res['state']=='Tamil Nadu']
df_state_ser = df_state.copy()
df_state_ser.drop(['district'],axis=1,inplace=True)
df_state_ser.reset_index(inplace=True)
df_state_ser.drop(['active'],axis=1,inplace=True)
df_state_ser.drop(['notes'],axis=1,inplace=True)
df_state_ser.drop(['index'],axis=1,inplace=True)
#df_state_ser.drop(['state'],axis=1,inplace=True)
df_state_ser.sort_values(by='date', ascending = False)
df_state_ser = df_state_ser.groupby(['date']).sum().reset_index()
df_state_ser['date'] = pd.to_datetime(df_state_ser['date'])
df_state_ser['tamil'] = df_state_ser['date'].dt.strftime("%d %b %y")
#df_state_ser.rename(columns={df_state_ser.columns[0]:'தேதி'}, inplace=True)
df_state_ser.rename(columns={df_state_ser.columns[1]:'உறுதிச்செய்யப்பட்டவை'}, inplace=True)
df_state_ser.rename(columns={df_state_ser.columns[3]:'குணமடைந்தவர்கள்'}, inplace=True)
df_state_ser.rename(columns={df_state_ser.columns[2]:'இறந்தவர்கள்'}, inplace=True)
df_state_ser.rename(columns={df_state_ser.columns[4]:'தேதி'}, inplace=True)
df_state_ser
附图给出了数据帧的输出。突出显示的第一个日期列已根据最后一列转换为区域设置日期格式
我能够使用数据框并使用我的语言环境日期格式获取绘图图,该格式也工作正常。
import plotly.graph_objs as go
import plotly.express as px
df_long_TN=pd.melt(df_state_ser, id_vars=['தேதி'], value_vars=['உறுதிச்செய்யப்பட்டவை','இறந்தவர்கள்','குணமடைந்தவர்கள்'])
fig = px.scatter( df_long_TN,x='தேதி', y="value", color="variable")
fig.update_traces(hovertemplate=None)
fig.update_layout(height=500, width= 605,font=dict(size=10,color="white"),xaxis_title="தேதி",paper_bgcolor= "#2D2D2D",plot_bgcolor="#2D2D2D",
yaxis=dict(tickformat=".f"), xaxis=dict(tickangle=270), legend=dict(x=0,y=1.3,traceorder="normal",font=dict(family="sans-serif",size=12)),
xaxis_showgrid=False, yaxis_showgrid=False, legend_title_text= 'மொத்தம்')
fig.show()
按照下图对代码进行了更改,并且能够毫无问题地获取带有区域设置日期的图表。
如果我使用上面相同的代码并在 Flask 应用程序中运行,我不会在图表中获取区域设置日期。我得到如下所述的输出。
需要您的输入/指针来修复 Flask 应用程序中的相同问题。
从 locale.setlocale(locale.LC_TIME, "ta_TA.utf8") 更改为 locale.setlocale(category=locale.LC_ALL,locale="Tamil") 修复了烧瓶的问题
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句