pd.read csv python code example

Example 1: 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 2: read_csv separator

import pandas as pd

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

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

Example 3: 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 4: python zfill

num = "7"

print(num.zfill(2)) # prints "07"

Example 5: np.c_ python

np.c_[np.array([1,2,3]), np.array([4,5,6])]

returns

array([[1, 4],
       [2, 5],
       [3, 6]])

Example 6: pandas read csv

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

Tags: