How to read csv file in pandas

Опубликовано: 30 Сентябрь 2024
на канале: Xpertji
47
0

How to read CSV file in pandas

We are going to use the panda's inbuild method called read_csv() to read the file. This method assumes a comma as the default separator. so we need not mention it. The code is as follows

import pandas as pd
df = pd.read_csv('C:/Users/user/Desktop/test.csv') #path of your file
print(df)

Read CSV file in pandas with a special separator or delimiter

If you have a special separator then you need to mention the separator. This separator may be a semicolon; Tab, Space, or any other separator. In our case the separator is a semicolon;
You need to specify the delimiter when reading the CSV file. You can do this using the parameter sep'' (or just sep).

import pandas as df
df = pd.read_csv('file.csv',sep = ';')

Share, Support, Subscribe!!!
YouTube: https://www.youtube.com/c/xpertji?sub...
Facebook:   / xpertji  
Twitter:   / xpertji  
Website : https://xpertji.com
patreon :   / xpertji