Pandas Series
Pandas
Constructing
import pandas as pd
data = ['item1', 'item2', 'item2']
series = pd.Series(['one', 'two', 'three'])
second = series[1]
Indexing
import pandas as pd
data = ['item1', 'item2', 'item2']
index = ['one','two',' three']
series = pd.Series(data = data, index=index)
item = series['two']
You can achieve the same effect as the prior code by using a dictionary as the data input.
dict = {"one":"item1", "two":"item2", "three":"item3"}
series = pd.Series(dict)
Casting Types
When creating a series, pandas will infer the type of the data from the inputted dataset.
You can specify a datatype that you want pandas to cast the data to using the dtype parameter.
series = pd.Series(data = [1,2,3], dtype="float")
Values
The values attribute returns a
numpy array
series = pd.Series(['one', 'two', 'three'])
#this is an ndarray
values = series.values