首页 > 解决方案 > UnicodeEncodeError:“latin-1”编解码器无法对位置 0-9 中的字符进行编码:序数不在范围内(256)

问题描述

我正在尝试在 Python 中使用 plotly 从时间序列制作交互式图表,但出现此错误:UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-9: ordinal not in range(256)

这是我的代码:

from pathlib import Path
import plotly
import chart_studio

chart_studio.tools.set_credentials_file(username='****',                                              
                                  api_key='*****')

import chart_studio.plotly as py
import plotly.graph_objs as go

from plotly.offline import init_notebook_mode, iplot
init_notebook_mode(connected=True)

def parser2(x):
    try:
        return datetime.strptime( x, '%Y-%m-%d %H:%M:%S')#
    except:
        return 0

filename = r'AT_2018_10last.csv'
datafolder = Path('C:\HiWi Rodriguez\AT 2018\Last Value')
pathfile = datafolder / filename
ts = read_csv(pathfile, header=0,  parse_dates=[0], index_col=0 ,  date_parser=parser2)#, dtype = dtypes)
ts.columns = ['A']
ts.plot()

AT = go.Scatter(x=ts.index, y=ts.A)

layout = go.Layout(title='Ambient Temperature', xaxis=dict(title='Date'),
                   yaxis=dict(title='[°C]'))

fig = go.Figure(data=AT, layout=layout)
py.iplot(fig, sharing='public')

标签: pythonplotly

解决方案



推荐阅读