pd read csv code example

Example 1: python read csv

# pip install pandas 
import pandas as pd

# Read the csv file
data = pd.read_csv('data.csv')

# Print it out if you want
print(data)

Example 2: how to import csv in pandas

import pandas as pd

df = pd.read_csv (r'Path where the CSV file is stored\File name.csv')
print (df)

Example 3: read_csv separator

import pandas as pd

df = pd.read_csv('data.csv',sep=';')

# also working
df = pd.read_csv('data.csv',delimiter=';')

Example 4: read csv uisng pandas

import pandas as pd #import pandas
#syntax: pd.read_csv('file_location/file_name.csv')
data = pd.read_csv('filelocation/fileName.csv') #reading data from csv

Example 5: pandas read csv

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

Example 6: 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))

Tags: