Python中文
首页
教程
问答
标签
搜索
登录
注册
Python Pandas错误类型错误:不支持/:“str”和“int”的操作数类型
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我正在努力学习如何在Python中使用熊猫。我对我的熊猫数据框做数学计算有问题。 现在我的数据帧看起来像这样:</p> <p>打印(标记)</p> <pre><code> 0 1 2 3 4 5 6 0 447366345 -2.04 -2.69 176.98 418.84 34.3167521 -118.4068498 1 447406197 -2.34 -2.18 176.88 418.77 34.3167522 -118.4068499 2 447446155 -2.63 -1.56 176.74 418.77 34.3167522 -118.4068499 3 447486653 -2.89 -0.95 176.58 418.84 34.3167522 -118.4068499 4 447526241 -3.12 -0.42 176.43 418.84 34.3167522 -118.4068499 5 447566373 -3.34 -0.07 176.32 418.84 34.3167522 -118.4068497 6 447606036 -3.56 0.05 176.26 418.66 34.3167523 -118.4068497 7 447645783 -3.77 -0.03 176.28 418.66 34.3167523 -118.4068497 8 447686269 -3.95 -0.31 176.43 418.95 34.3167523 -118.4068497 def data_reader(filename, rowname): with open(filename, newline='') as fp: yield from (row[1:] for row in csv.reader(fp, skipinitialspace=True) if row[0] == rowname) mike = pd.DataFrame.from_records(data_reader('data.csv', 'mike')) </code></pre> <p>现在假设我要取0行除以1000</p> <pre><code>mark_time = mark[0] / 1000 </code></pre> <p>这会产生错误</p> <pre><code> TypeError: unsupported operand type(s) for /: 'str' and 'int' </code></pre> <p>我猜是因为当前我的数据帧不被视为INT,所以我继续做了以下工作:</p> <pre><code>mark_time = float (mark[0] / 1000) </code></pre> <p>不过,这也给了我同样的错误。有人能解释一下原因吗?</p> <p>我的第二个问题是当它涉及到阴谋。我已经很好地学习了matplotlib,我想在我的Panda数据帧上使用它。目前我的做法是:</p> <pre><code>fig1 = plt.figure(figsize= (10,10)) ax = fig1.add_subplot(311) ax.plot(mike_time, mike[0], label='mike speed', color = 'red') plt.legend(loc='best',prop={'size':10}) </code></pre> <p>我可以用我的数据帧替换mike_time和mike[0]吗?</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>您需要使用pandas read_csv,它将自动为每个列分配最合适的类型。如果有任何混合类型的列,它将警告您。然后可以再次运行它,显式设置类型。</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何提高Djang的410误差
7 回答
如何提高doc2vec模型中两个文档(句子)的余弦相似度?
8 回答
如何提高Docker的日志限制?|[输出已剪裁,达到日志限制100KiB/s]
10 回答
如何提高DQN的性能?
9 回答
如何提高EasyOCR的准确性/预测?
5 回答
如何提高Euler#39项目解决方案的效率?
2 回答
如何提高F1成绩进行分类
5 回答
如何提高FaceNet的准确性
8 回答
如何提高fft处理的精度?
10 回答
如何提高Fibonacci实现对大n的精度?
8 回答
如何提高Flask与psycopg2的连接时间
3 回答
如何提高FosterCauer变换的scipy.signal.invres()的数值稳定性?
6 回答
如何提高gae查询的性能?
9 回答
如何提高GANs用于时间序列预测/异常检测的结果
5 回答
如何提高gevent和tornado组合的性能?
4 回答
如何提高googleappengin请求日志的吞吐量
5 回答
如何提高googlevision文本识别的准确性
9 回答
如何提高groupby/apply效率
5 回答
如何提高Gunicorn中的请求率
10 回答
如何提高G中的文件编码转换
2 回答