🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to Pandas Notes
Topic #5

Pandas DataFrames


What is a DataFrame?

A Pandas DataFrame is a 2 dimensional data structure, like a 2 dimensional array, or a table with rows and columns.

Example

import pandas as pd

data = {
  "calories": [420, 380, 390],
  "duration":
[50, 40, 45]
}

#load data into a DataFrame object:
df = pd.DataFrame(data)

print(df)

Locate Row

As you can see from the result above, the DataFrame is like a table with rows and columns.

Pandas use the loc attribute to return one or more specified row(s)

Example

#refer to the row index:
print(df.loc[0])

Note: This example returns a Pandas Series.

Example

#use a list of indexes:
print(df.loc[[0, 1]])

Note: When using [], the result is a Pandas DataFrame.


Named Indexes

With the index argument, you can name your own indexes.

Example

import pandas as pd

data = {
  "calories": [420, 380, 390],
  "duration":
[50, 40, 45]
}

df = pd.DataFrame(data, index = ["day1", "day2",
"day3"])

print(df)

Locate Named Indexes

Use the named index in the loc attribute to return the specified row(s).

Example

#refer to the named index:
print(df.loc["day2"])

Load Files Into a DataFrame

If your data sets are stored in a file, Pandas can load them into a DataFrame.

Example

import pandas as pd

df = pd.read_csv('data.csv')

print(df)

Note: You will learn more about importing files in the next chapters.

Want to go beyond the notes?

Join CodingNow 2.0's Pandas course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Pandas DataFrames – FAQs

Quick answers about learning Pandas DataFrames in Pandas.

This free note from CodingNow 2.0 explains Pandas DataFrames in Pandas — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Pandas topic on CodingNow 2.0, including Pandas DataFrames, is 100% free with no signup required.
With focused practice, most students grasp Pandas DataFrames in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now