Q1. You have a dictionary of student grades: {''Alice'':85, ''Bob'':92, ''Charlie'':78, ''Diana'':95}. Convert it to a pandas Series and compute the average grade.
import pandas as pd
grades = pd.Series({''Alice'':85, ''Bob'':92, ''Charlie'':78, ''Diana'':95})
mean = grades.mean() # 87.5Series is one-dimensional labeled array. Access by index: grades[''Alice''] → 85. Great for key-value data.Q2. Create a DataFrame from a list of lists: data = [[''Alice'',25,85],[''Bob'',22,92],[''Charlie'',27,78]] with columns [''Name'',''Age'',''Score'']. Then display the first two rows.
df = pd.DataFrame(data, columns=[''Name'', ''Age'', ''Score''])
head = df.head(2) # rows 0 and 1DataFrame is 2D labeled structure. Also df.tail(2) for last rows. Essential for data exploration.Q3. Load a CSV file ''sales.csv'' into a DataFrame. Then inspect its info, shape, and descriptive statistics.
df = pd.read_csv(''sales.csv'')
df.info() # data types and non‑null counts
df.shape # (rows, columns)
df.describe() # count, mean, std, min, quartiles, max for numeric columnsThis is the first step in any data analysis.Q4. You have a DataFrame with column ''price''. Add a new column ''price_usd'' assuming 1 unit = 1.2 USD. Update the DataFrame.
df[''price_usd''] = df[''price''] * 1.2
# or: df = df.assign(price_usd = df[''price''] * 1.2)Operations are vectorized. Use df.drop(''price_usd'', axis=1) to remove column.Q5. Create a DataFrame with missing values in column ''age''. Use fillna to replace missing with the median age.
df = pd.DataFrame({''age'': [25, None, 30, None, 35]})
median = df[''age''].median()
df[''age''].fillna(median, inplace=True)This imputes missing values. Also can use df.fillna(method=''ffill'') for forward fill.