Python ValueError:无法将字符串转换为浮点-sns.tsplot,time-使用字符串标记x轴

Python ValueError:无法将字符串转换为浮点-sns.tsplot,time-使用字符串标记x轴,python,time-series,seaborn,axis-labels,Python,Time Series,Seaborn,Axis Labels,文件“输入”(列错误,这就是我在read\u csv中使用header=0的原因) 代码 当前,绘图仅显示沿x轴的顺序数字。 将y轴标记为当前显示的x=4、5、6对应的值是标准偏差,这并不完全正确。。但撇开这一点不谈,有没有办法用字符串标记x轴?我注意到可以使用日期/时间来执行此操作 下面是我目前收到的错误。奇怪的是,read.columns.values.tolist()列表的第6项会出现ValueError。但是,这不起作用。有人知道这件事吗?我非常珍惜,谢谢 Traceback (mos

文件“输入”(列错误,这就是我在
read\u csv
中使用header=0的原因)

代码

当前,绘图仅显示沿x轴的顺序数字。 将y轴标记为当前显示的x=4、5、6对应的值是标准偏差,这并不完全正确。。但撇开这一点不谈,有没有办法用字符串标记x轴?我注意到可以使用日期/时间来执行此操作

下面是我目前收到的错误。奇怪的是,
read.columns.values.tolist()
列表的第6项会出现ValueError。但是,这不起作用。有人知道这件事吗?我非常珍惜,谢谢

Traceback (most recent call last):
  File "/Users/hsl/work_dir/eclipse/ISSDA/src/GMM_ppr.py", line 32, in <module>
  time = read.columns.values.tolist())
  File "/anaconda/lib/python3.5/site-packages/seaborn/timeseries.py", line 280, in tsplot
  x = df_c.columns.values.astype(np.float)
ValueError: could not convert string to float: 'week_score'
回溯(最近一次呼叫最后一次):
文件“/Users/hsl/work_dir/eclipse/ISSDA/src/GMM_ppr.py”,第32行,在
时间=read.columns.values.tolist())
文件“/anaconda/lib/python3.5/site packages/seaborn/timeseries.py”,第280行,在tsplot中
x=df_c.columns.values.astype(np.float)
ValueError:无法将字符串转换为浮动:“周分数”

Time只是不接受列表中的字符串。 为了使用字符串作为x轴的标签,我确实找到了使用xticks的解决方法

toc = time.time()
#header = 0 replaces the headers with names specified
read = pd.read_csv('input', sep='\t', index_col= 0, header =0, names =['meter', 'overn_PR', 'breakf_PR', 'day_PR', 'evng_PR', 'std_year', 'week_score', 'season_score'], encoding= 'utf-8')
read.drop('meter', 1, inplace=True)
read['std_year'] = round(read['std_year']/4, 2)
print(read.columns.values.tolist())

input = read.as_matrix()
string_val = read.columns.values.tolist()

sns.tsplot(data=input, err_style='unit_traces',\
       value = 'energy use [kWh]')
plt.xticks(range(7),string_val) #sets the x axis with the supplied list

plt.show()

tic = time.time()
print(tic-toc)

您能添加几行CSV以便复制该问题吗?谢谢您的想法。我更新了。
Traceback (most recent call last):
  File "/Users/hsl/work_dir/eclipse/ISSDA/src/GMM_ppr.py", line 32, in <module>
  time = read.columns.values.tolist())
  File "/anaconda/lib/python3.5/site-packages/seaborn/timeseries.py", line 280, in tsplot
  x = df_c.columns.values.astype(np.float)
ValueError: could not convert string to float: 'week_score'
toc = time.time()
#header = 0 replaces the headers with names specified
read = pd.read_csv('input', sep='\t', index_col= 0, header =0, names =['meter', 'overn_PR', 'breakf_PR', 'day_PR', 'evng_PR', 'std_year', 'week_score', 'season_score'], encoding= 'utf-8')
read.drop('meter', 1, inplace=True)
read['std_year'] = round(read['std_year']/4, 2)
print(read.columns.values.tolist())

input = read.as_matrix()
string_val = read.columns.values.tolist()

sns.tsplot(data=input, err_style='unit_traces',\
       value = 'energy use [kWh]')
plt.xticks(range(7),string_val) #sets the x axis with the supplied list

plt.show()

tic = time.time()
print(tic-toc)