Extract items at given positions of a series using Pandas

In this python pandas program, we will extract items at given positions of a series using pandas.

Steps to solve the program
  1. Import pandas library as pd.
  2. Create a series using pd.Series().
  3. Extract items at given positions of a series using df.take(positions) where positions are the index no of values that we want to extract.
  4. Print the output.
				
					import pandas as pd
df = pd.Series([3,0,3,2,2,0,3,3,2])
positions = [1,4,7]
print("Original Series:")
print(df)
result = df.take(positions)
print("Extract items at given positions of the said series:")
print(result)
				
			

Output :

				
					Original Series:
0    3
1    0
2    3
3    2
4    2
5    0
6    3
7    3
8    2
dtype: int64
Extract items at given positions of the said series:
1    0
4    2
7    3
dtype: int64

				
			

calculate the frequency of each value of a series

convert the first and last character of each word to upper case in each word of a given series

Leave a Comment