Python: Pandas
Created: March 05, 2020
-
Installed via Anaconda or Pip.
-
import pandas as pd -
pd.Seriesandpd.DataFrameare the two workhorses of pandas.
Series
-
A Series is a one-dimensional array-like object containing a sequence of values and an associated array of data labels, called its index.
-
pd.Series([1st, 2nd,...,nth]): define a series with zero-based indexing.Calling the object itself will return a graphical representation of indexes and values.
-
Series.values: return an array of the values. -
Series.index: return a RangeIndex object that holds start, stop, and step values.
Declare an
pd.Series([1st,2nd,...,nth], index=['l1','l2',...,'ln'])
E
*l = label
>>> seriesObj = pd.Series([4, 7, -5, 3])
>>> seriesObj
0 4
1 7
2 -5
3 3
################################################################################
>>> seriesObj.values
array([4, 7, -5, 3])
>>> seriesObj.index
RangeIndex(start=0, stop=4, step=10 # like range(4)
################################################################################
>>> seriesObj2 = pd.Series([4, 7, -5, 3], index=['d', 'b', 'a', 'c'])
>>> seriesObj2
d 4
b 7
a -5
c 3