By the way, hope someone can provide a file teach me how to use Python for CSV file reading and writing (the more detailed, the better)
Thank you all fellows in the
CodePudding user response:
According to the code, dense eggs. CSV is the CSV file name in the current directory,You can also use the specified path
With the open (' d:/dense eggs. CSV. Newlinge=") as csvfile:
Python read CSV
One kind of method is commonly used
1, using the open method
Data_file=open (' data. CSV ', 'r')
Data_list=data_file. Readlines ()
2, the import CSV
Your example
3, pandas. Read_csv
To do after read CSV analysis statistics, then suggest directly use 3 kinds of methods, direct read in pd
All code, baidu search, more is,
CodePudding user response:
The import CSV# reference CSV module,
Csv_file=open (' demo. CSV ', 'w', newline=', encoding="utf-8")
# call open () function opens the CSV file, the incoming parameters: the name of the file "demo. CSV", "w" write mode, newline=', encoding="utf-8",
Writer.=the CSV writer (csv_file)
# use CSV. Writer () function creates a writer object,
Writer. Writerow ([' movie ', 'douban score'])
# call object writer writerow () method, can write a line of text in the CSV file "film" and "douban score,"
Writer. Writerow ([' galactic guards', '8.0'])
# in the CSV file is written to one line of text "galaxy convoy" and "8.0",
Writer. Writerow ([' avengers alliance ', '8.1'])
# in the CSV file is written to one line of text "avengers alliance" and "8.1",
Csv_file. Close ()
# write complete, close the file you're done!
reference