我想将csv文件列中的值(数字作为文本)自动放入json文件中。从结果中,我想设置一个键并在csv列中获取该值。如何在jupyter笔记本中解决这个问题?
不好意思-我是个流血的初学者。
import csv
with open('blabla.csv', newline='') as f:
reader = csv.reader(f)
for row in reader:
print(row)
答案 0 :(得分:0)
您非常接近。
bla.csv:
3-85460-115-8
4-85460-115-8
5-85460-115-8
6-85460-115-8
代码:
import csv
with open('bla.csv', newline='') as f:
reader = csv.reader(f)
for row in reader:
url = "http://data.bib.uni-mannheim.de/malibu/isbn/gbv.php?isbn=" + str(row[0]) + "&format=json"
print(url)
thing = urlretrieve(url)
# Do what you want to do with the thing... :-)
输出:
http://data.bib.uni-mannheim.de/malibu/isbn/gbv.php?isbn=3-85460-115-8&format=json
http://data.bib.uni-mannheim.de/malibu/isbn/gbv.php?isbn=4-85460-115-8&format=json
http://data.bib.uni-mannheim.de/malibu/isbn/gbv.php?isbn=5-85460-115-8&format=json
http://data.bib.uni-mannheim.de/malibu/isbn/gbv.php?isbn=6-85460-115-8&format=json
如果有任何问题,请随时发表评论。就像knh190所说的那样,下次请以文本形式而不是图像形式发布代码。 :-)
答案 1 :(得分:0)
import csv
with open('blabla1.csv', newline='') as f:
reader = csv.reader(f)
for row in reader:
url = "http://blabla2.php?isbn=" + str(row[1]) + "&format=json"
print(url)