在Python中读取和写入CSV文件中的数据
我是Python的新手,我在Python中使用CSV文件时遇到了一些问题.请帮帮我
I am new to Python and I am having some problems with CSV files in Python. Please help me out
-
如何在Python中打开和读取存在于其他目录中的csv文件?我知道我们可以做到
How do I open and read csv files in Python which are present in some other directory? I know we can do
import csv
f = open('attendees1.csv')
只要我的程序文件和csv文件在同一目录中即可.但是,如何提供指向另一个目录中的csv文件的链接?
As long as my program file and csv file is in the same directory. But how do I provide a link to the csv file sitting in another directory?
我有一个包含多行和多列的列表,如何将这些数据传输到csv文件并将其保存在特定位置?
I have a list with multiple rows and columns, how do I transfer this data to a csv file and save it down in a particular location?
请帮帮我
open()
是文件,可以是诸如C:\Program Files\file.csv
的绝对路径,也可以是诸如../../file.csv
的相对路径,此处..
指当前目录上方的目录,而.
指当前目录
First argument of open()
is file, which can be an absolute path like C:\Program Files\file.csv
or a relative one like ../../file.csv
here ..
refers to the directory above the current directory and .
refers to the current directory.
import csv
with open('../path/to/file.csv', 'w') as f:
csv_writer = csv.writer(f)
csv_writer.writerows(your_row_data)
your_row_data
是列表列表.