You are on page 1of 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 Series
Pandas Series
Pandas DataFrames
Pandas Read CSV
Pandas Read JSON ❮ Previous Next ❯
Pandas Analyzing Data

Cleaning Data
Cleaning Data
What is a Series?
Cleaning Empty Cells A Pandas Series is like a column in a table.
Cleaning Wrong Format
Cleaning Wrong Data It is a one-dimensional array holding data of any type.
Removing Duplicates

Correlations Example Get your own Python Server

Pandas Correlations Create a simple Pandas Series from a list:

Plotting import pandas as pd


Pandas Plotting
a = [1, 7, 2]

Quiz/Exercises
myvar = pd.Series(a)
Pandas Editor
print(myvar)

Try it Yourself »

Labels
If nothing else is specified, the values are labeled with their index number. First value has index 0, second value has index 1 etc.

This label can be used to access a specified value.

COLOR PICKER
Example
Return the first value of the Series:

print(myvar[0])

Try it Yourself »

Create Labels
With the index argument, you can name your own labels.

Example
Create your own labels:

import pandas as pd

a = [1, 7, 2]

myvar = pd.Series(a, index = ["x", "y", "z"])

print(myvar)

Try it Yourself »

When you have created labels, you can access an item by referring to the label.

ADVERTISEMENT
Example
Return the value of "y":

print(myvar["y"])

Try it Yourself »

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

Key/Value Objects as Series


You can also use a key/value object, like a dictionary, when creating a Series.

Example
Create a simple Pandas Series from a dictionary:

import pandas as pd

calories = {"day1": 420, "day2": 380, "day3": 390}

myvar = pd.Series(calories)

print(myvar)

Try it Yourself »

Note: The keys of the dictionary become the labels.

To select only some of the items in the dictionary, use the index argument and specify only the items you want to include in the
Series.

Example
Create a Series using only data from "day1" and "day2":

import pandas as pd

calories = {"day1": 420, "day2": 380, "day3": 390}

myvar = pd.Series(calories, index = ["day1", "day2"])

print(myvar)

Try it Yourself »

DataFrames
Data sets in Pandas are usually multi-dimensional tables, called DataFrames.

Series is like a column, a DataFrame is the whole table.

Example
Create a DataFrame from two Series:

import pandas as pd

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

myvar = pd.DataFrame(data)

print(myvar)

Try it Yourself »

You will learn about DataFrames in the next chapter.

Test Yourself With Exercises

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

pd. (mylist)

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