Create a subset of a given series using Pandas

In this python pandas program, we will create a subset of a given series using Pandas library.

Steps to solve the program
  1. Import pandas library as pd.
  2. Create a series using pd.Series().
  3. Now create a subset of a given series using logic in this case, df[df < 40].
  4. 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
				
			

add some data to an existing series

change the order of the index of a given series

Leave a Comment