编写带有多个变量的CSV,带有字面名称Python
我是Python的新手,所以请友善...我需要编写一个带有多个变量和字段名称的CSV文件。我找到了不同的帖子: 的CSV
with open('lat_lon', 'w') as csvfile:
fieldnames = ['lat','lon']
writer=csv.writer(csvfile, delimiter=',',fieldnames=fieldnames)
writer.writeheader
writer.writerows(zip(lat, long)
如果您能帮助我,那就太好了!
顺便说一句,我在Mac上使用Python 3.10.4和Pycharm Community Edition 2021.3.3。
谢谢!
Im very new to python so please be kind... I need to write a csv file with multiple variables and a fieldname. I found a different post:
Writing a CSV with multiple variables
But i have 0 clue how to add a fieldname. I know that it has to be something like:
with open('lat_lon', 'w') as csvfile:
fieldnames = ['lat','lon']
writer=csv.writer(csvfile, delimiter=',',fieldnames=fieldnames)
writer.writeheader
writer.writerows(zip(lat, long)
if you can help me that would be great!
btw I'm using python 3.10.4 and pycharm community edition 2021.3.3 on mac.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CSV文件中的字段名称不超过该文件的第一行。因此,在开始时,您可以简单地编写CSV文件中所需字段名称的行:
Field names in a csv file are no more than the first row of that file. So at the beginning you can simply write a row with the desired field names in your csv file: