CSV
comma-separated files
Reading csv
In this tutorial, we look at the usage of the following date time methods and attributes
pd.read_csv() #read a csv file into pandas Dataframe
df.to_csv #write a pandas DataFrame into a csv file
The most commonly used read function is read_csv
.There are a number of functions that convert text data into a DataFrame. Most of these functions have optional arguments that handle column names, missing values, datetime parsing, skipping rows, dealing with thousand separated comma's, and so on.
import pandas as pd
df = pd.read_csv('data/mydata.csv', sep=';')
df.head()
For instance, if you want to read a small number of rows you can specify that with nrows
df = pd.read_csv('data/mydata.csv', sep=';', nrows=10)
Using the DataFrames to_csv
method, we can write the data out to a comma-separated file:
df.to_csv('output/output.csv')
Last updated
Was this helpful?