[英]Python: list of elements must be not strings
I am working on a project which use some specific library called "orkg" and based on Python.我正在开发一个项目,该项目使用一些名为“orkg”的特定库并基于 Python。 I am using a function called "save_dataset" to save some data in a csv file.我正在使用名为“save_dataset”的 function 将一些数据保存在 csv 文件中。
After executing the function, I am receiving an error:执行 function 后,我收到一个错误:
File "<pyshell#16>", line 1, in <module>
datasetID = orkg.resources.save_dataset(file="data.csv", label=["cc_variant", "Date","NEE"], dimensions=[
File "/usr/local/lib/python3.8/dist-packages/orkg/client/resources.py", line 130, in save_dataset
cDataStructureDefinition = self.client.classes.find_or_add(label="qb:DataStructureDefinition").content['id']
TypeError: list indices must be integers or slices, not str
This is the code that I am using:这是我正在使用的代码:
datasetID = orkg.resources.save_dataset(file="data.csv", label=["cc_variant", "Date","NEE"], dimensions=[
("Fallow", 2016-10-18, 5231861),
("Fallow", 2016-10-19, 3675274),
("Fallow", 2016-10-24, 3459082),
("Mix4", 2016-10-18, -51686837),
("Mix12", 2016-10-18, -61711000),
("Mustard", 2016-10-18, -18224568),
("Mix4", 2016-10-19, -10263776),
("Mix12", 2016-10-19, -43155887),
("Mustard", 2016-10-19, -13904121),
("Mustard", 2016-10-24, -11409939),
("Mix12", 2016-10-24, -40021260),
("Mix4", 2016-10-24, -17533208)])
So I tried to change the values from string in this way:所以我尝试以这种方式更改字符串中的值:
datasetID = orkg.resources.save_dataset(file="data.csv", label=["cc_variant", "Date","NEE"], dimensions=[
(Fallow, 2016-10-18, 5231861), (Fallow, 2016-10-19, 3675274), (Fallow, 2016-10-24, 3459082), (Mix4, 2016-10-18, -51686837),
(Mix12, 2016-10-18, -61711000), (Mustard, 2016-10-18, -18224568), (Mix4, 2016-10-19, -10263776),
(Mix12, 2016-10-19, -43155887), (Mustard, 2016-10-19, -13904121), (Mustard, 2016-10-24, -11409939),
(Mix12, 2016-10-24, -40021260), (Mix4, 2016-10-24, -17533208)]
But I get also this error:但我也得到这个错误:
NameError: name 'Fallow' is not defined
And this is the link to the documentation of the orkg method: https://orkg.readthedocs.io/en/latest/examples/resources.html#create-a-resource-of-tabular-data这是 orkg 方法文档的链接: https://orkg.readthedocs.io/en/latest/examples/resources.html#create-a-resource-of-tabular-data
The content of the csv file: csv文件内容:
cc_variant;Date;NEE
Fallow;18.10.2016;5.231.861
Fallow;19.10.2016;3.675.274
Fallow;24.10.2016;3.459.082
Mix4;18.10.2016;-51.686.837
Mix12;18.10.2016;-61.711.000
Mustard;18.10.2016;-18.224.568
Mix4;19.10.2016;-10.263.776
Mix12;19.10.2016;-43.155.887
Mustard;19.10.2016;-13.904.121
Mustard;24.10.2016;-11.409.939
Mix12;24.10.2016;-40.021.260
Mix4;24.10.2016;-17.533.208
Looking at the documentation, it looks like dimensions should be a list of strings that label each column.查看文档,看起来尺寸应该是 label 每列的字符串列表。 The following code assumes the CSV has 4 columns: "Fallow", "Mix4", "Mix12", "Mustard"以下代码假设 CSV 有 4 列:“Fallow”、“Mix4”、“Mix12”、“Mustard”
datasetID = orkg.resources.save_dataset(file="data.csv", label=["Name of this dataset"],
dimensions=["cc_variant", "Date", "NEE"])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.