0% found this document useful (0 votes)
9 views1 page

Pandas DataFrames

This document provides an overview of Pandas DataFrames. It defines a DataFrame as a 2D data structure like a table with rows and columns. It demonstrates how to create a simple DataFrame from a dictionary of data, and how to access rows and columns using loc and indexing. It also shows how to name the indexes, load data from files into a DataFrame, and includes exercises to test comprehension.

Uploaded by

ahmed salem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

Pandas DataFrames

This document provides an overview of Pandas DataFrames. It defines a DataFrame as a 2D data structure like a table with rows and columns. It demonstrates how to create a simple DataFrame from a dictionary of data, and how to access rows and columns using loc and indexing. It also shows how to name the indexes, load data from files into a DataFrame, and includes exercises to test comprehension.

Uploaded by

ahmed salem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

 Tutorials  Exercises  Get Certified  Services  Bootcamps Spaces Sign Up Log in

Dark mode
Dark code
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP BOOTSTRAP HOW TO W3.CSS C C++ C# REACT R JQUERY DJANGO   

Pandas Tutorial ADVERTISEMENT

Pandas HOME
Pandas Intro
Pandas Getting Started

Pandas DataFrames
Pandas Series
Pandas DataFrames
Pandas Read CSV
Pandas Read JSON ❮ Previous Next ❯
Pandas Analyzing Data

Cleaning Data
Cleaning Data
What is a DataFrame?
Cleaning Empty Cells A Pandas DataFrame is a 2 dimensional data structure, like a 2 dimensional array, or a table with rows and columns.
Cleaning Wrong Format
Cleaning Wrong Data
Removing Duplicates Example Get your own Python Server

Correlations Create a simple Pandas DataFrame:

Pandas Correlations
import pandas as pd

Plotting data = {
Pandas Plotting "calories": [420, 380, 390],
"duration": [50, 40, 45]
Quiz/Exercises }

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

print(df)

Result

calories duration
0 420 50
1 380 40
2 390 45

COLOR PICKER
Try it Yourself »

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
Return row 0:

#refer to the row index:


print(df.loc[0])

Result

calories 420
duration 50
Name: 0, dtype: int64

Try it Yourself »

Note: This example returns a Pandas Series.

ADVERTISEMENT

Example
Return row 0 and 1:

#use a list of indexes:


print(df.loc[[0, 1]])

Result
calories duration
0 420 50
1 380 40

Try it Yourself »

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

Get Certified!
school
w3 s
2
CE

02

Complete the Pandas modules, do the exercises, take the exam, and you will become w3schools certified! TI 2
R

FI .
ED

$10 ENROLL

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

Example
Add a list of names to give each row a name:

import pandas as pd

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

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

print(df)

Result

calories duration
day1 420 50
day2 380 40
day3 390 45

Try it Yourself »

Locate Named Indexes


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

Example
Return "day2":

#refer to the named index:


print(df.loc["day2"])

Result

calories 380
duration 40
Name: day2, dtype: int64

Try it Yourself »

Load Files Into a DataFrame


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

Example
Load a comma separated file (CSV file) into a DataFrame:

import pandas as pd

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

print(df)

Try it Yourself »

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

Test Yourself With Exercises

Exercise:
Insert the correct Pandas method to create a DataFrame.

pd. (data)

Submit Answer »

Start the Exercise

❮ Previous Log in to track progress Next ❯

ADVERTISEMENT

ADVERTISEMENT

Spaces Upgrade Newsletter Get Certified Report Error

Top Tutorials Top References Top Examples Get Certified


HTML Tutorial HTML Reference HTML Examples HTML Certificate
CSS Tutorial CSS Reference CSS Examples CSS Certificate
JavaScript Tutorial JavaScript Reference JavaScript Examples JavaScript Certificate
How To Tutorial SQL Reference How To Examples Front End Certificate
SQL Tutorial Python Reference SQL Examples SQL Certificate
Python Tutorial W3.CSS Reference Python Examples Python Certificate
W3.CSS Tutorial Bootstrap Reference W3.CSS Examples PHP Certificate
Bootstrap Tutorial PHP Reference Bootstrap Examples jQuery Certificate
PHP Tutorial HTML Colors PHP Examples Java Certificate
Java Tutorial Java Reference Java Examples C++ Certificate
C++ Tutorial Angular Reference XML Examples C# Certificate
jQuery Tutorial jQuery Reference jQuery Examples XML Certificate

FORUM | ABOUT

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we
cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2023 by Refsnes Data. All Rights Reserved.


W3Schools is Powered by W3.CSS.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy