Pandas read_csv | Mastering in Python Pandas Library

Pandas Read CSV File in Python

What is CSV File

A CSV is a comma separated values file which allows to store data in tabular format. That data includes numbers and text in plain text form. CSV is an extension of any file or spreadsheet .

Advantages of CSV File
1. Universally used
2. Easy to read
3. Easy to understand
4. Quick to create

How to Read or Import CSV File in Python IDLE or IDE

import pandas as pd

 Pandas.read_csv function used to import csv file
 for more information about pandas.read_csv (pd.read_csv) function use help function

help(pd.read_csv)
pd.read_csv('F:\\Machine Learning\\DataSet\\student_results.csv')
Output >>>
    StudentID	Class	StudyHrs	SleepingHrs	SocialMedia	MobileGames	Percantege
0	1001	    10	    2	        9	        3	        5	        50
1	1002	    10	    6	        8	        2	        0	        80
2	1003	    10	    3	        8	        2	        4	        60
3	1004	    11	    0	        10	        1	        5	        45
4	1005	    11	    4	        7	        2	        0	        75
5	1006	    11	    10	        7	        0	        0	        96
6	1007	    12	    4	        6	        0	        0	        80
7	1008	    12	    10	        6	        2	        0	        90
8	1009	    12	    2	        8	        2	        4	        60
9	1010	    12	    6	        9	        1	        0	        85

This datastructure is dataframe, we can also import series datastructure using pd.read_csv function

pd.read_csv('F:\\Machine Learning\\DataSet\\Top 10 IT Companies in India.csv')
Output >>>
          
    Top 10 IT Companies in India
0	TCS
1	Infosys
2	Tech Mahindra
3	Wipro
4	HCL Technologies
5	L&T Infotech
6	Mindtree
7	Mphasis
8	Oracle Financial Services
9	Rotla India

This is series datastructure

To know where is these files store in your computer system use ‘os’ library

import os
print(os.getcwd())
C:\Users\T-Rex\Pandas Practical

Download dataset click here – student_results

Download dataset click here – Top 10 IT Companies in India

Download Jupyter file pandas read_csv source code

Visit the official site of pandas.read_csv

Leave a Reply

Top