pandas read a csv file in collumns code example

Example 1: Column names reading csv file python

df = pd.read_csv('file.csv', names=['a', 'b', 'c'], header=None)
df.rename(columns = {'a':'A', 'b':'B', 'c':'C'}, inplace = True) 
df.to_csv('file.csv')

Example 2: pandas read csv

import pandas as pd
cereal_df = pd.read_csv("/tmp/tmp07wuam09/data/cereal.csv")
cereal_df2 = pd.read_csv("data/cereal.csv")

# Are they the same?
print(pd.DataFrame.equals(cereal_df, cereal_df2))

Example 3: read a csv file in pandas

you should be in the same dir as .py file 

df = pd.read_csv('your_file_name.csv')

Example 4: read_csv

>>> pd.read_csv('data.csv')

Tags:

Misc Example