[Python] Reading CSV files

csvfile.csv


Mr. A,1,Month
Mr. B,2,fire
Mr. C,3,water

main.py


import csv

#Read the file
csv_file = open("csvfile.csv", "r", encoding="utf-8", errors="", newline="" )
print(type(csv_file))
"""
<class '_io.TextIOWrapper'>
"""

#Parses the CSV string.
csvData = csv.reader(csv_file, delimiter=",", doublequote=True, lineterminator="\r\n", quotechar='"', skipinitialspace=True)
print(type(csvData))
"""
<class '_csv.reader'>
"""

#_csv.Convert reader type to list
csvData = [row for row in csvData]
print(type(csvData))
print(csvData)
"""
<class 'list'>
[['Mr. A', '1', 'Month'], ['Mr. B', '2', 'fire'], ['Mr. C', '3', 'water']]
"""

Recommended Posts

[Python] Reading CSV files
Reading and writing csv files
Reading and writing CSV and JSON files in Python
Reading .txt files with Python
[Introduction for beginners] Reading and writing Python CSV files
Transpose CSV files in Python Part 1
[Python] Loading csv files using pandas
Python CSV file reading and writing
Handle Excel CSV files with Python
Csv in python
[Easy Python] Reading Excel files with openpyxl
[Easy Python] Reading Excel files with pandas
Reading pyc file (Python 3.5.2)
I tried reading a CSV file using Python
Csv tinkering with python
Reading and writing fits files with Python (memo)
Python --Tagging MP3 files
Read Python csv file
python external file reading
[Python] Master the reading of csv files. List of main options for pandas.read_csv.
Example of reading and writing CSV with Python
Character code for reading and writing csv files with python ~ windows environment ver ~
Reading CSV data from DSX object storage Python code
Remove headings from multiple format CSV files with python
Read csv with python pandas
python document reading descriptor HowTo
Sorting image files with Python (2)
Sort huge files with python
Sorting image files with Python (3)
Sorting image files with Python
Integrate PDF files with Python
Write to csv with Python
Decompress multiple compressed files (Python)
Download csv file with python
Memorandum (Countermeasures against Unicode Decode Error when reading CSV files)
[Python: UnicodeDecodeError] One of the error solutions when reading CSV
[Python] Until scraping beginners save J-League standings to CSV files
[Python] Easy reading of serial number image files with OpenCV
Make apache log csv with python
Python
Recursively unzip zip files with python
[Python] Write to csv file with Python
Handle csv files with Django (django-import-export)
How to import CSV and TSV files into SQLite with Python
Output to csv file with Python
Manipulate files and folders in Python
[Python] POST wav files with requests [POST]
Read and use Python files from Python
uproot: Python / Numpy based library for reading and writing ROOT files
Handling of JSON files in Python
Decrypt files encrypted with OpenSSL with Python 3
Notes for me python csv graph
Sort large text files in Python
Reading and writing NetCDF with Python
Multi-line size specification reading with python
Read files in parallel with Python
python documentation reading socket programming HOWTO
Reading and writing text in Python
Sorting files by Python naming convention
Extract strings from files in Python
Reading from text files and SQLite in Python (+ Pandas), R, Julia (+ DataFrames)