无法将字符串转换为浮点错误. [英] Could not convert string to float error.

查看:559
本文介绍了无法将字符串转换为浮点错误.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在X和Y轴上绘制值".我不想在图表中放入任何数据,只需将时间 DID (如下所示)标记为Axis

I would like to plot values onto the X and Y axis'. I do not want to put any data in the graph, just label the Axis' with Time and DID(As seen below)

这是我的代码:

import pandas as pd 
import matplotlib.pyplot as plt
from matplotlib import style 
style.use('ggplot')


df = pd.read_csv('Test_Sheet_1.csv')

Time = df.ix[8:, 1]

DID = df.ix[1, 6:13]


ax1 = plt.subplot2grid((6,6), (0,0), rowspan=1, colspan=6)

ax1.plot(Time)

plt.show() 

我收到此错误:

Could not convert string to float.

是的,我要放在x和y轴上的是字母,而不是数字,因此此错误有效.我该如何解决这个问题?有没有简单的方法可以从图中绘制这些DID和时间,而不会出现此错误?

yes what i am trying to put on the x, and y axis are letters, not numbers, so this error is valid. how do i fix this problem? Is there any easy way to plot these DID's and Times from the graph without getting this error?

此外,我是python的新手,并且一般来说都进行编码,因此,如果我的问题不清楚,请告诉我,我将尽力解决它.

Also, i am new to python, and coding in general, so if my question isnt clear please let me know, and i will try my best to fix it.

非常感谢您!

推荐答案

时间"列的类型可能不是DateTime.

The Time column may not be of type DateTime.

这将与显式转换一起工作吗?

Will this work with an explicit conversion?

ax1.plot(pd.to_datetime(Time))

这篇关于无法将字符串转换为浮点错误.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆