Create Pandas Series with Custom index
Create Pandas Series with custom index using “Series” method of Pandas library and index parameter.
In this Pandas tutorial we are creating a list of colors and using that list we create a pandas series. Pandas series objects have immense use in single column data like time series data and custom indexing makes data wrangling much easier.
# Imports
import pandas as pd
# Let's create a series
color = ['Red', 'Blue', 'Green', 'Red', 'Yellow']
s = pd.Series(color)
s
0 Red 1 Blue 2 Green 3 Red 4 Yellow dtype: object
s100 = pd.Series(color, index=[100,101,102,103,104])
s100
100 Red 101 Blue 102 Green 103 Red 104 Yellow dtype: object
# Get Index
s100.index
Int64Index([100, 101, 102, 103, 104], dtype='int64')
Related Resources:
- Create Pandas series | Pandas tutorial Create Pandas Series Create Pandas Series with “Series” method of Pandas library. In this Pandas tutorial we are creating a...
- Pandas series from Dictionary | Pandas Tutorial Pandas Series from Dictionary Create pandas series from dictionary using “Series” method of Pandas library. In the below example we...
- Pandas groupby tutorial | Understand Group by Pandas Groupby Group by is an important technique in Data Analysis and Pandas groupby method helps us achieve it. In...
- Reset Index in Pandas Dataframe | Pandas tutorial Reset Index Reset index in pandas using “reset_index” method of pandas dataframe. When we perform slicing or filtering operations on...
- Not Operation in Pandas Conditions | Pandas tutorial Not Operation in Pandas Conditions Apply not operation in pandas conditions using (~ | tilde) operator. In this Pandas tutorial...
- One Hot Encoding | What is one hot encoding? One Hot Encoding | Dummies One Hot encoding means splitting categorical variable into multiple binary variables. “One hot” means at...
- Gini Index vs Entropy Information gain | Decision Tree | No 1 Guide Gini index vs Entropy Gini index and entropy is the criterion for calculating information gain. Decision tree algorithms use information...
- Get value from index in Numpy array | Numpy tutorial Value from Index in Numpy Get value from index in numpy array using python like slicing. In below examples we...
- Learn Pandas easily with mini tutorials Pandas Learn Pandas with easy mini tutorials. Pandas is one of the major tools for Data Scientists. Pandas enables us...
- Loop through rows in pandas | Iterate over rows Loop through rows in Pandas Use “iterrows” method of pandas dataframe to loop through rows # Imports import pandas as...