DataFrame in Pandas
In this lesson, the DataFrame object of pandas is explained.
DataFrame
A DataFrame
can be described as a 2-D array or matrix. It has data stored in it just like an excel spreadsheet with multiple columns and rows. Unlike Series
which only has one index, each value in a DataFrame
object is associated with a row index as well as a column index.
In the following code snippet, a CSV file containing cancer registration statistics of 2017 is read in a DataFrame
.
import pandas as pddf = pd.read_csv('cancer_stats.csv') # Read from csv fileprint (df.head()) # This method prints the first five rows in the dataframe
It can be seen from the output that every row has a specific index already assigned to it
On Line 3, data from the cancer_stats.csv file is read using the read_csv()
function of pandas, which takes the file name as its argument.
On Line 5, the head()
method, without any parameters, prints the first five rows from the DataFrame
...
Get hands-on with 1400+ tech skills courses.