Series Exercises#

Section Title: Series Exercises

Question-1#

Create a Series named fruit_name with the index [‘Banana’, ‘Melon’, ‘Apple’, ‘Orange’, ‘Cherry’] and values [200, 450, 275, 190, 230]. - — Give the name ‘Fruit Cost’ to the Series.

  • Add a new row with the index Pear and value 500.

  • Change the value of Melon to 950.

  • Remove the row with the index Orange from the Series.

  • Update the indices to [‘Blackberry’, ‘Apricot’, ‘Grapefruit’, ‘Kiwi’, ‘Nectarine’].

  • Sort the Series in ascending order.

  • Display the largest value along with its corresponding index.

Question-2#

Run the following code to import Apple stock values and their corresponding dates as Series.

apple = pd.read_csv('https://raw.githubusercontent.com/datasmp/datasets/main/stock.csv')['APPLE']
dates = pd.read_csv('https://raw.githubusercontent.com/datasmp/datasets/main/stock.csv')['Date']
  • Set the dates as the index of the Apple Series.

  • Display the following details about the updated Apple Series:

    • Total number of rows

    • The last 5 indices

    • The last 5 values

    • The median of the values

    • The highest two values.

Question-3#

Create an array of 100 random integers between 2 and 4 (excluding 1 and 5).

  • Store the integers in a Series and set the index as S-1, S-2, …, S-100.

  • Display the following details about the Series:

    • The number of times the value 3 appears.

    • The most common element in the Series.

    • The least common element in the Series.

    • The number of even values in the Series.

    • The sum of all even values in the Series.

Question-4#

Generate 1,000 randomly chosen passwords, each consisting of two lowercase letters and two numbers in any order.

  • Store these passwords in a Series with the index labeled as Person-1, Person-2, …, Person-1000.

  • Check for duplicate passwords.

  • Display the duplicate passwords.

  • Remove duplicates, keeping only one instance of each password.

  • Check for duplicates again.

Question-5#

Generate 1,000 random numbers using a Gaussian distribution and store them in a Series. Calculate the following:

  • The count of grades less than 20.

  • The count of grades greater than 80.

  • The average of grades greater than 80, rounded to the nearest hundredth.

  • The count of grades between 45 and 60.