Learn Before
Code
Creating a Series
- Passing in a list of values with or without the index
import pandas as pd list1 = ["a","b","c"] s1 = pd.Series(list1) s2 = pd.Series(["a", "b", "c"], index = [1, 2, 3])
- From a dictionary. If an index isn't passed, the dictionary keys are used to create an index
import pandas as pd d1 = {"a" : 1, "b" : 2, "c" : 3} s1 = pd.Series(d1)
- From a scalar value. The value is repeated to match the length of the index, and the index must be provided.
import pandas as pd s = pd.Series(1, index = ["x", "y", "z"])
0
1
Updated 2020-09-07
Tags
Data Science