pandas from csv 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: command to read file in python using pandas

import panda as pd 

file_csv = pd.read_csv("file path")  ## as csv format
file_excel = pd.read_excel("file path") ## as excel format
file_json = pd.read_json("file path") ## as json format
file_html = pd.read_html("file path") ## as html format
file_localClipboard = pd.read_clipboard("file path") ## as clipboard format
file_MSExcel = pd.read_excel("file path") ## as excel format
file_HDF5 = pd.read_hdf("file path") ## as hdf5 fomrmat
file_Feather = pd.read_feather("file path") ## as feather format
file_msgpack = pd.read_msgpack("file path") ## as msgpack format
file_stata = pd.read_stata("file path") ## as stata format
file_SAS = pd.read_sas("file path") ## as SAS format
file_paythonPickle = pd.read_pickle("file path") ## as paython_pickle format
file_SQL = pd.read_sql("file path") ## as sql format
file_google_big_query = pd.read_gbq("file path") ## as google big query

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: how to set up dataframe from csv

import pandas as pd

column_names = ['sepel lengh', 'sepel width', 'petal lengh', 'petal width', 'class']
iris = pd.read_csv('iris.csv', names=column_names)

print(iris)

Example 6: pandas read csv

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

Tags:

Go Example