Computer Science, asked by tanmaykhandelwal962, 7 months ago


Q3. Write a python program to sort the values of Series object si in ascending order and store these values
in Series object S2​

Answers

Answered by Manjiri67
2

Explanation:

Use Series.sort_values() function to sort the elements of the given series object in lexicographical order.

# importing pandas as pd

import pandas as pd

  

# Creating the Series

sr = pd.Series(['New York', 'Chicago', 'Toronto', 'Lisbon', 'Rio', 'Moscow'])

  

# Create the Datetime Index

didx = pd.DatetimeIndex(start ='2014-08-01 10:00', freq ='W', 

                     periods = 6, tz = 'Europe/Berlin') 

  

# set the index

sr.index = didx

  

# Print the series

print(sr)

Now we will use Series.sort_values() function to sort the elements of the given series object in ascending order.

# sort the values in ascending order

sr.sort_values()

Now we will use Series.sort_values() function to sort the elements of the given series object in descending order.

# sort the values in descending order

sr.sort_values(ascending = False)

 hope \: it \: helps \: you. \:  \:  \\  < please \: mark \: as \: brainlist  >

Similar questions