Sunday, September 2, 2018

How To Read A CSV File In Pandas | Pandas Tutorial 2 | Big Data Tutorials | Codeing School

In this article, I teach how to read a CSV file in Pandas. Pandas is an open source, BSD-licensed library providing high-performance, easy-to-use data structures and data analysis tools for the Python programming language.

Reading A CSV File In Python Pandas | Data Science and Big Data Tutorials | Codeing School
Reading A CSV File In Python Pandas | Data Science and Big Data Tutorials

Today’s topic: How to read a CSV file in Pandas/Jupyter Notebook

**1st you need a data set. If you have not any kind of data set, you can download it, Click Here.


Reading a CSV File:

Step 1. Upload the CSV file on your work folder.

Step 2. Click On upload.


Reading A CSV File In Python Pandas | Data Science and Big Data Tutorials | Codeing School
Click On upload

Step 3. Choose the CSV file.

Reading A CSV File In Python Pandas | Data Science and Big Data Tutorials | Codeing School
Choose the CSV file


Step 4. And Upload the CSV file.

Reading A CSV File In Python Pandas | Data Science and Big Data Tutorials | Codeing School
And Upload the CSV file


To Read this CSV file:


import pandas as pd
df1 = pd.read_csv('Indian_states_analysis.csv')
df1


Output


Reading A CSV File In Python Pandas | Data Science and Big Data Tutorials | Codeing School
Image 1. Read CSV

Logic: pd.read_csv(), this is syntax for read CSV files. pd.read_csv('Indian_states_analysis.csv'), “Indian_states_analysis.csv” is the name of the CSV file. Write the CSV file name within, ‘’ à mean single inverted comma.


Print top 4 rows:

df1.head(4)


Output:

Reading A CSV File In Python Pandas | Data Science and Big Data Tutorials | Codeing School
Print top 4 rows


Print last 3 rows:

df1.tail(3)

Output:

Reading A CSV File In Python Pandas | Data Science and Big Data Tutorials | Codeing School
Print last 3 rows



Find Datatype:


print(df1['name_of_city'].dtype)

Output:
object

print(df1['dist_code'].dtype)

Output:
int64

Logic: See the Image no. 1, 'name_of_city', is the 1st column in our data set. When I write the syntax à print(df1['name_of_city'].dtype), it gave me ‘Object’ as output. Because, when Pandas didn’t understand the data type of the elements, it gives Object as output. Next,
See the Image no. 1, 'dist_code', is the 4th column in our data set.
When I write the syntax à print(df1['dist_code'].dtype), it give me ‘int64’, because it is an integer value.

Reading A CSV File In Python Pandas | Data Science and Big Data Tutorials | Codeing School
Find Data Type




If you have, any quarry please comment below.



0 comments:

Post a Comment