首页 > 解决方案 > 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”就在这里出现了!

标签: pythonpython-3.xmatplotlib

解决方案


推荐阅读