3.1. Series Create

3.1.1. From Python sequence

  • list

  • tuple

  • set

  • frozenset

import pandas as pd
import numpy as np


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

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

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

pd.Series(['a', 'b', 'c', 'd'])
# 0    a
# 1    b
# 2    c
# 3    d
# dtype: object
import pandas as pd

list('abcd')
# ['a', 'b', 'c', 'd']

pd.Series(list('abcd'))
# 0    a
# 1    b
# 2    c
# 3    d
# dtype: object

3.1.2. From Python range

import pandas as pd

pd.Series(range(4))
# 0    0
# 1    1
# 2    2
# 3    3
# dtype: int64

3.1.3. From Numpy ndarray

import pandas as pd
import numpy as np

pd.Series(np.arange(4.0))
# 0    0.0
# 1    1.0
# 2    2.0
# 3    3.0
# dtype: float64

3.1.4. From Date Range

import pandas as pd


pd.Series(pd.date_range(start='1969-07-16', end='1969-07-24'))
# 0   1969-07-16
# 1   1969-07-17
# 2   1969-07-18
# 3   1969-07-19
# 4   1969-07-20
# 5   1969-07-21
# 6   1969-07-22
# 7   1969-07-23
# 8   1969-07-24
# dtype: datetime64[ns]

3.1.5. Length

import pandas as pd

s = pd.Series([1, 2, 3, 4])

len(s)
# 9

3.1.6. Assignments

3.1.6.1. Series Create Float

  • Assignment: Series Create Float

  • Last update: 2020-10-01

  • Complexity level: easy

  • Lines of code to write: 5 lines

  • Estimated time of completion: 3 min

  • Filename: solution/series_create_float.py

English:
  1. Create pd.Series with 5 float numbers

  2. One of those values must be None

Polish:
  1. Stwórz pd.Series z 5 liczbami zmiennoprzecinkowymi

  2. Jedną z tych wartości musi być None

3.1.6.2. Series Create Randint

  • Assignment: Series Create Randint

  • Last update: 2020-10-01

  • Complexity level: easy

  • Lines of code to write: 5 lines

  • Estimated time of completion: 3 min

  • Filename: solution/series_create_randint.py

English:
  1. Set random seed to zero

  2. Create pd.Series with 10 random digits (int from 0 to 9)

Polish:
  1. Ustaw ziarno losowości na zero

  2. Stwórz pd.Series z 10 losowymi cyframi (int from 0 to 9)

3.1.6.3. Series Create Even

  • Assignment: Series Create Even

  • Last update: 2020-10-01

  • Complexity level: easy

  • Lines of code to write: 5 lines

  • Estimated time of completion: 3 min

  • Filename: solution/series_create_even.py

English:
  1. Create pd.Series with 10 even numbers

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

3.1.6.4. Series Create Dates

  • Assignment: Series Create Dates

  • Last update: 2020-10-01

  • Complexity level: easy

  • Lines of code to write: 5 lines

  • Estimated time of completion: 3 min

  • Filename: solution/series_create_dates.py

English:
  1. Gagarin flown to space on 1961-04-12

  2. Armstrong set foot on the Moon on 1969-07-21

  3. Create pd.Series with days between Gagarin's launch and Armstrong's first step

  4. How many days passed?

Polish:
  1. Gagarin poleciał w kosmos w 1961-04-12

  2. Armstrong postawił stopę na Księżycu w 1969-07-21

  3. Stwórz pd.Series z dniami pomiędzy startem Gagarina a pierwszym krokiem Armstronga

  4. Jak wiele dni upłynęło?