Complete the code to convert all names in the DataFrame to lowercase.
import pandas as pd data = {'Name': ['Alice', 'Bob', 'CHARLIE']} df = pd.DataFrame(data) df['Name_lower'] = df['Name'].str.[1]() print(df)
The str.lower() method converts all characters in the string to lowercase.
Complete the code to convert all city names in the DataFrame to uppercase.
import pandas as pd data = {'City': ['Paris', 'london', 'New York']} df = pd.DataFrame(data) df['City_upper'] = df['City'].str.[1]() print(df)
The str.upper() method converts all characters in the string to uppercase.
Fix the error in the code to convert the 'Fruit' column to lowercase.
import pandas as pd data = {'Fruit': ['Apple', 'BANANA', 'Cherry']} df = pd.DataFrame(data) df['Fruit_lower'] = df['Fruit'].str.[1]() print(df)
The correct method to convert strings to lowercase is str.lower(). Other options are invalid method names.
Fill both blanks to create a dictionary with fruit names in uppercase as keys and their lengths as values, only for fruits longer than 5 letters.
fruits = ['apple', 'banana', 'cherry', 'date'] lengths = {fruit.[1](): len(fruit) for fruit in fruits if len(fruit) [2] 5} print(lengths)
We use upper() to convert fruit names to uppercase keys. The condition > 5 filters fruits with length greater than 5.
Fill all three blanks to create a dictionary with uppercase fruit names as keys, their lowercase versions as values, only for fruits with names longer than 4 letters.
fruits = ['Apple', 'Banana', 'Fig', 'Grape'] result = {fruit.[1](): fruit.[2]() for fruit in fruits if len(fruit) [3] 4} print(result)
The keys are uppercase fruit names using upper(). The values are lowercase using lower(). The condition > 4 filters fruits longer than 4 letters.