In this python pandas program, we will create a subset of a given series using Pandas library.
Steps to solve the program
- Import pandas library as pd.
- Create a series using pd.Series().
- Now create a subset of a given series using logic in this case, df[df < 40].
- Print the output.
import pandas as pd
df = pd.Series([10,25,69,74,33,54,21])
print(df)
print("Subset of the above Data Series:")
new = df[df < 40]
print(new)
Output :
0 10
1 25
2 69
3 74
4 33
5 54
6 21
dtype: int64
Subset of the above Data Series:
0 10
1 25
4 33
6 21
dtype: int64