Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用python将列表转换为csv格式_Python_Csv - Fatal编程技术网

使用python将列表转换为csv格式

使用python将列表转换为csv格式,python,csv,Python,Csv,如何转换为csv格式,如 a = [{'year': 222, 'title': 'abc'}, {'year': 111, 'title': 'ddd'}] 我使用的aws lambda无法导入熊猫使用 使用 你为什么需要熊猫导入csv…此外,这基本上是对上一个问题的重复。你的“傻瓜”是什么意思?我承认我是python的傀儡。我只是想更多地了解python,问一个太简单的问题:“我使用aws lambda,我不能导入熊猫”,意思是我不想导入熊猫。为什么你还问我“你为什么需要熊猫?”真有趣?重

如何转换为csv格式,如

a = [{'year': 222, 'title': 'abc'}, {'year': 111, 'title': 'ddd'}]

我使用的aws lambda无法导入熊猫

使用

使用


你为什么需要熊猫<代码>导入csv…此外,这基本上是对上一个问题的重复。你的“傻瓜”是什么意思?我承认我是python的傀儡。我只是想更多地了解python,问一个太简单的问题:“我使用aws lambda,我不能导入熊猫”,意思是我不想导入熊猫。为什么你还问我“你为什么需要熊猫?”真有趣?重复。我的意思是为什么你认为你需要熊猫?当有其他方法在没有外部库的情况下编写CSV时。为什么需要熊猫<代码>导入csv…此外,这基本上是对上一个问题的重复。你的“傻瓜”是什么意思?我承认我是python的傀儡。我只是想更多地了解python,问一个太简单的问题:“我使用aws lambda,我不能导入熊猫”,意思是我不想导入熊猫。为什么你还问我“你为什么需要熊猫?”真有趣?重复。我的意思是为什么你认为你需要熊猫?当有其他方法在没有外部库的情况下编写CSV时。对不起,我使用aws lambda不能使用“with open('names.CSV','w',newline='')作为csvfile:”,你能帮我吗?obj=s3.get_对象(Bucket='excelfile23987',Key='ttttttt.json')
body=obj['body']
a=body.read().decode('utf-8')
[{'year':222,'title':'abc'},{'year':111,'title':'ddd'}]我的原始“a”资源显示在上面。我在“writer.writerow(d)”中有一个错误。“errorMessage”:“'str'对象没有属性'keys'”,“errorType”:“AttributeError”请帮助我不要问多个问题。我回答了你的问题。然后你告诉我你不能使用文件。我改变了我的答案。现在你想要另一个答案。抱歉。因为我认为减少一些无用的代码。这个动作产生这个问题。没关系。非常感谢你已经回答我两次。抱歉,我使用AWSλ不能使用。用open('names.csv','w',newline='')作为csvfile:,你能帮我吗?obj=s3.get_对象(Bucket='excelfile23987',Key='ttttttt.json')
body=obj['body']
a=body.read().decode('utf-8')
\'year':222,'title':'abc'},{'year':111,'title':'ddd}]我原来的“a”资源显示在上面。我在“writer.writerow(d)”中有一个错误““errorMessage”:“'str'对象没有属性'keys'”,“errorType”:“AttributeError”“请帮助我不要问多个问题。我已经回答了你的问题。然后你告诉我你不能使用文件。我改变了我的答案。现在你想要另一个答案。抱歉。因为我认为减少一些无用的代码。这个动作产生这个问题。没关系。非常感谢你已经回答我两次了。
b =     year, title
        222, abc
        111, ddd
import csv
import io


a = [{'year': 222, 'title': 'abc'}, {'year': 111, 'title': 'ddd'}]
f = io.StringIO()
fieldnames = ['year', 'title']
writer = csv.DictWriter(f, fieldnames=fieldnames)
writer.writeheader()
for d in a:
    writer.writerow(d)

print(f.getvalue())

out:
year,title
222,abc
111,ddd