Complete the code to sort the Series in ascending order.
import pandas as pd s = pd.Series([3, 1, 2]) s_sorted = s.[1]()
The sort_values() method sorts the Series by its values in ascending order.
Complete the code to sort the Series in descending order.
import pandas as pd s = pd.Series([3, 1, 2]) s_sorted_desc = s.sort_values([1]=False)
The ascending parameter controls the sort order. Setting it to True sorts ascending, False sorts descending.
Fix the error in the code to sort the Series by index.
import pandas as pd s = pd.Series([3, 1, 2], index=['b', 'a', 'c']) s_sorted = s.[1]()
The sort_index() method sorts the Series by its index labels.
Fill both blanks to create a dictionary of word lengths for words longer than 3 letters.
words = ['apple', 'bat', 'carrot', 'dog'] lengths = {word: [1] for word in words if len(word) [2] 3}
We use len(word) to get the length, and filter words with length greater than 3 using >.
Fill all three blanks to create a dictionary with uppercase keys and values greater than 1.
data = {'a': 1, 'b': 2, 'c': 3}
result = { [1]: [2] for k, v in data.items() if v [3] 1 }Keys are converted to uppercase with k.upper(). Values are kept as v. We filter values greater than 1 using >.