python - Python - TypeError: 1 is not a string -
问题描述
我正在尝试执行下面的代码,但由于某种原因它引发了错误“TypeError:1 不是字符串”。
我不明白为什么,因为当我运行它将数据集更改为带有整数的简单列表时,它可以工作。
我以这种方式在熊猫中导入数据集:
import pandas as pd
import matplotlib.pylab as plt
data = pd.read_csv('sedimento.csv', encoding ='latin-1', delimiter=';', decimal=',')
导入运行良好,生成的数据集如下所示:
data = pd.DataFrame({"xmin": [1, 1, 2], "ymin": [-13.2, -14.2, -12.76], "ymax": [-12.2, -13.2, -11.76]})
因此,我定义了参数以在 map 和 lambda 函数中绘制图:
xw = 1
xmin = data['xmin']
ymin = data['ymin']
ymax = data['ymax']
plt.figure()
list(map(lambda x,y,z:plt.broken_barh([(x,xw)], (y, z), facecolors = 'blue'), xmin,ymin,ymax))
所以“TypeError: 1 is not a string”就在这里出现了!
解决方案
推荐阅读
- java - 有没有办法记录在 hikari 中获得连接所需的时间?
- python - python django django.db.utils.OperationalError: table pybo_question has no column named content 错误?
- jsp - jsp:include 不能包含二进制文件
- regex - 消极展望的替代方案
- javascript - 试图在滚动视频上获得模糊效果
- python - 熊猫将迭代添加列添加到数据框
- soap - SSRS 报告 - XML 查询
- reactjs - 如何在打字稿中的变体“临时”的抽屉组件上设置 zIndex
- python - 如何将数据插入到 Azure SQL 数据库上的表中,并且通过 Airflow DAG 使用 Azure Key Vault 对少数列进行加密
- c - Cygwin 无法链接 libexif 程序