[PYTHON] Read CSV file: pandas

Make a note of how to read the csv file

Contents of csv file

test.png Check with a simple one like the one above

Import pandas

import pandas as pd

Read and display

data = pd.read_csv('csv file path/file name.csv')
print(data)

The csv file is read in the first line and displayed in the second line. The following is displayed

csv表示.png

Header information

print(data.columns)

When I run the above code, I get the following header information

インデックス1.png

The first line of the csv file is recognized as a header

Header assignment: Serial number

data = pd.read_csv('csv file path/file name.csv',header=None)
print(data)

連番.png

The header of 0 1 2 3 4 is set separately from the contents of the csv file.

Header assignment: Specify

data = pd.read_csv('csv file path/file name.csv',names=('A','B','C','D','E'))
print(data)

指定.png

The specified A B C D E is set as the header.

Use index as a time series

Csv file used

test2.png

data = pd.read_csv('csv file path/file name.csv',names=('A','B','C','D','E'),index_col=0, parse_dates=True))
print(data)

表示2.png

print(data.index)

スクリーンショット 2020-06-06 22.11.03.png

index is recognized as datetime.

Recommended Posts

Read CSV file: pandas
Read Python csv file
Read and write csv file
Read csv with python pandas
Read file
Read pandas data
Read CSV file with python (Download & parse CSV file)
[pandas] .csv file reading and display method
How to read CSV files in Pandas
Download Pandas DataFrame as a CSV file
Read CSV and analyze with Pandas and Seaborn
How to read a CSV file with Python 2/3
Read and format a csv file mixed with comma tabs with Python pandas
Read Python csv data with Pandas ⇒ Graph with Matplotlib
[Python] How to read excel file with pandas
Reading pandas format file
File read overhead measurement
[Python] How to read a csv file (read_csv method of pandas module)
Have pandas read the zip file on the web
[Introduction to Pandas] Read a csv file without a column name and give it a column name
Read the csv file and display it in the browser
How to convert JSON file to CSV file with Python Pandas
Every time I try to read a csv file using pandas, I get a numpy error.
Read and write a file
Read / write between BigQuery ↔ Pandas
Write and read a file
AHC task (1) Reading CSV file
Download csv file with python
[Python] Open the csv file in the folder specified by pandas
[Python] Read the csv file and display the figure with matplotlib
How to read an Excel file (.xlsx) with Pandas [Python]
How to paste a CSV file into an Excel file using Pandas
[Python] Loading csv files using pandas
[Python] Write to csv file with Python
Output to csv file with Python
Pandas
Format the CSV file of "National Holiday" of the Cabinet Office with pandas
Python CSV file reading and writing
[Python] Read a csv file with a large data size using a generator
Ignore # line and read in pandas
Summary of processes often performed in Pandas 1 (CSV, Excel file related operations)
Read CSV file with Python and convert it to DataFrame as it is
[Python] How to convert db file to csv
[Note] Read a file from another directory
Load csv with duplicate columns in pandas
[Python] Convert csv file delimiters to tab delimiters
Read all csv files in the folder
Let's read the RINEX file with Python ①
[GO language] Let's read a YAML file
Read and write csv files with numpy
Read the file line by line in Python
Read the file line by line in Python
Read the file by specifying the character code.
Read Python csv and export to txt
Read a character data file with numpy
Grouping csv and getting minimum value (pandas)
Load csv with pandas and play with Index
[python] Read html file and practice scraping
[Python] Read the specified line in the file
[Automation] Read mail (msg file) with Python
Various ways to read the last line of a csv file in Python