4.6. Series Create

4.6.1. Creating

  • 1-dimensional data structure similar to ndarray

  • Has numerical index

4.6.1.1. int

import pandas as pd


pd.Series([1, 2, 3])
# 0    1
# 1    2
# 2    3
# 3    4
# dtype: int64

4.6.1.2. float

import pandas as pd


pd.Series([1., 2., 3., 4.])
# 0    1.0
# 1    2.0
# 2    3.0
# 3    4.0
# dtype: float64
import pandas as pd


pd.Series([1, 2, np.nan, 4])
# 0    1.0
# 1    2.0
# 2    NaN
# 3    4.0
# dtype: float64
import pandas as pd


pd.Series([1, 2, np.nan, 4])
# 0    1.0
# 1    2.0
# 2    NaN
# 3    4.0
# dtype: float64

4.6.1.3. str

import pandas as pd


pd.Series(['a', 'b', 'c'])
# 0    a
# 1    b
# 2    c
# dtype: object

4.6.1.4. dates

import pandas as pd


dates = pd.date_range(start='2020-01-01', end='2020-01-06')

pd.Series(dates)
# 0   2020-01-01
# 1   2020-01-02
# 2   2020-01-03
# 3   2020-01-04
# 4   2020-01-05
# 5   2020-01-06
# dtype: datetime64[ns]

4.6.2. Assignments

4.6.2.1. Even Numbers

  1. Stwórz pd.Series z 10 liczbami parzystymi

  2. Podnieś wszystkie elementy do kwadratu

  3. Dodaj 5 do każdego z elementów