Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

In [1]: import pandas as pd

# a. Create a series with 5 elements and display sorted series on index and values separatel
series_a = pd.Series([3, 1, 5, 2, 4], index=['e', 'a', 'c', 'b', 'd'])
print("Original Series:")
print(series_a)
print("\nSorted Series on Index:")
print(series_a.sort_index())
print("\nSorted Series on Values:")
print(series_a.sort_values())

# b. Create a series with N elements with some duplicate values


series_b = pd.Series([1, 2, 3, 3, 4, 4, 5, 5])
print("\nOriginal Series with Duplicate Values:")
print(series_b)

# Find the minimum and maximum ranks assigned to the values using 'first' and 'max' methods
print("\nMinimum Rank (assigned to values using 'first' method):")
print(series_b.rank(method='first', ascending=True))
print("\nMaximum Rank (assigned to values using 'max' method):")
print(series_b.rank(method='max', ascending=True))

# c. Display the index value of the minimum and maximum element of a Series
print("\nIndex value of the minimum element:", series_b.idxmin())
print("Index value of the maximum element:", series_b.idxmax())
Original Series:
e 3
a 1
c 5
b 2
d 4
dtype: int64

Sorted Series on Index:


a 1
b 2
c 5
d 4
e 3
dtype: int64

Sorted Series on Values:


a 1
b 2
e 3
d 4
c 5
dtype: int64

Original Series with Duplicate Values:


0 1
1 2
2 3
3 3
4 4
5 4
6 5
7 5
dtype: int64

Minimum Rank (assigned to values using 'first' method):


0 1.0
1 2.0
2 3.0
3 4.0
4 5.0
5 6.0
6 7.0
7 8.0
dtype: float64

Maximum Rank (assigned to values using 'max' method):


0 1.0
1 2.0
2 4.0
3 4.0
4 6.0
5 6.0
6 8.0
7 8.0
dtype: float64

Index value of the minimum element: 0


Index value of the maximum element: 6

In [2]: print('By- Aaryan Pandey 13591')

By- Aaryan Pandey 13591

In [ ]:

You might also like