Complete the code to reshape the DataFrame from wide to long format using pandas.
long_df = df.melt(id_vars=[1])To reshape data from wide to long format, you specify the columns to keep fixed using id_vars. Here, ['Name', 'Date'] are the identifier columns.
Complete the code to pivot the DataFrame to wide format using pandas.
wide_df = df.pivot(index=[1], columns='Month', values='Sales')
The index parameter specifies the column to use as new row labels. Here, 'Store' is used as the index.
Fix the error in the code to correctly stack the DataFrame columns into a Series.
stacked = df.[1]()The stack() method compresses columns into a single Series with a MultiIndex, which is the correct way to stack columns.
Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.
{word: [1] for word in words if [2]The dictionary comprehension maps each word to its length using len(word). The condition keeps only words with length greater than 3.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their counts if count is greater than 0.
result = [1]: [2] for [3] in data.items() if [2] > 0}
The comprehension maps each key converted to uppercase (k.upper()) to its value v, iterating over keys k and values v from data.items(). It includes only items where the value is greater than 0.