Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

reading
data
csv
python
excel

Reading data for data science

Educative Answers Team

There are various instances when the functioning of a program requires a large amount of data; this kind of data is often so large that it’s practically impossible to input using the keyboard and console.

Now, it is the programming norm to read data from files. Three of the most popular file formats for data are:

  • comma-separated variables (.csv)

  • pickle (.pkl)

  • Excel (.xlsx)

Data that consists of thousands of records are mostly stored in one of the three file formats mentioned above. The Pandas library in Python is one of the most widely used libraries for data reading, cleaning, and analysis.

Let’s have a look at how to read data from each of the above-mentioned formats using Pandas:

1. Reading a CSV file

The read_csv method of the Pandas library takes a CSV file as a parameter and returns a dataframe.

import pandas as pd
df = pd.read_csv('my_csv.csv')

2. Reading a pickle file

The read_pickle method of the Pandas library takes a pickle file as a parameter and returns a dataframe.

import pandas as pd
df = pd.read_pickle('my_pkl.pkl')

3. Reading an Excel file

The read_excel method of the Pandas library takes an excel file as a parameter and returns a dataframe.

import pandas as pd
df = pd.read_excel('my_excel.xlsx')

Once the data has been read into a data frame, display the data frame to see if the data has been read correctly.

RELATED TAGS

reading
data
csv
python
excel
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring