HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
A Pandas Series is like a column in a table
A Pandas Series is like a column in a table.
It is a one-dimensional array holding data of any type.
Create a simple Pandas Series from a list:
import pandas as pd
a = [1, 7, 2]
myvar = pd.Series(a)
print(myvar)
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.
Return the first value of the Series:
print(myvar[0])
With the index
argument, you can name your own labels.
Create you own labels:
import pandas as pd
a = [1, 7, 2]
myvar = pd.Series(a, index = ["x", "y", "z"])
print(myvar)
When you have created labels, you can access an item by referring to the label.
Return the value of "y":
print(myvar["y"])
#buy_course_btn { text-decoration:none !important; background-color:#04AA6D; width:auto; border-radius:25px; padding-top:10px; padding-bottom:10px; font-family: 'Source Sans Pro', sans-serif; } #buy_course_btn { background-color:#059862!important; }
You can also use a key/value object, like a dictionary, when creating a Series.
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)
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.
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)
Data sets in Pandas are usually multi-dimensional tables, called DataFrames.
Series is like a column, a DataFrame is the whole table.
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)
You will learn about DataFrames in the next chapter.