Series is a one-dimensional labeled array capable of holding any data type (integers, strings, floating point numbers, Python objects, etc.). It has to be remembered that unlike Python lists, a Series will always contain data of the same type.
Let’s see how to create a Pandas Series from Dictionary.
Series() method without
In this case, dictionary keys are taken in a sorted order to construct index.
Code #1 : Dictionary keys are given in sorted order.
A 10 B 20 C 30 dtype: int64
Code #2 : Dictionary keys are given in unsorted order.
B 20 C 30 D 10 dtype: int64
Series() method with
In this case, the values in data corresponding to the labels in the index will be assigned.
Code #1 : Index list is passed of same length as the number of keys present in dictionary.
B 10 C 80 A 50 dtype: int64
Code #2 : Index list is passed of greater length than the number of keys present in dictionary in this case, Index order is persisted and the missing element is filled with NaN (Not a Number).
B 10 C 80 D NaN A 50 dtype: float64
- Creating Series from list, dictionary, and numpy array in Pandas
- Add a Pandas series to another Pandas series
- Creating a Pandas Series from Lists
- Creating a Pandas Series
- Creating a dataframe from Pandas series
- How to convert a dictionary to a Pandas series?
- Python | Creating Multidimensional dictionary
- Python | Pandas series.cumprod() to find Cumulative product of a Series
- Python | Pandas Series.str.replace() to replace text in a series
- Python | Pandas Series.astype() to convert Data type of series
- Python | Pandas Series.cumsum() to find cumulative sum of a Series
- Python | Pandas series.cummax() to find Cumulative maximum of a series
- Python | Pandas Series.cummin() to find cumulative minimum of a series
- Python | Pandas Series.nonzero() to get Index of all non zero values in a series
- Python | Pandas Series.mad() to calculate Mean Absolute Deviation of a Series
- Convert a series of date strings to a time series in Pandas Dataframe
- Convert Series of lists to one Series in Pandas
- Converting Series of lists to one Series in Pandas
- Pandas - Get the elements of series that are not present in other series
- Creating a Pandas dataframe using list of tuples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.