Theory Questions
What is Pandas in Python?
What are the two primary data structures provided by Pandas?
How can you create a Pandas Series?
How can you create a Pandas DataFrame?
What is the role of an index in Pandas?
How can you read data from a CSV file into a DataFrame using Pandas?
What is the purpose of the head()
function in Pandas?
How can you select a specific column from a DataFrame?
What is the difference between the loc[]
and iloc[]
methods in Pandas?
How can you handle missing data in a DataFrame?
Pandas PPT
Programming Questions
How can you create an empty DataFrame with columns “Name” and “Age”?
How do you drop a column named “Salary” from a DataFrame?
How can you find the number of unique values in a column “Category” of a DataFrame?
How can you rename the index label “row_label” of a DataFrame to “new_label”?
How do you calculate the mean of a numeric column “Values” in a DataFrame?
How can you create a new DataFrame that includes only rows with even values in a column “Numbers”?
How can you group a DataFrame by the “Category” column and calculate the sum of values in each group?
How can you convert a DataFrame’s index to a column named “Index”?
How do you calculate the correlation coefficient between columns “A” and “B” in a DataFrame?
How can you create a new DataFrame by merging two existing DataFrames based on a common column “ID”?
Output Questions
import pandas as pd
data = {‘Name’: [‘Alice’, ‘Bob’, ‘Charlie’],
‘Age’: [25, 30, 28]}
df = pd.DataFrame(data)
print(df)
import pandas as pd
df = pd.read_csv(‘data.csv’)
print(df)
import pandas as pd
data = {‘Name’: [‘Alice’, ‘Bob’, ‘Charlie’],
‘Age’: [25, 30, 22]}
df = pd.DataFrame(data)
names = df[‘Name’]
print(names)
import pandas as pd
data = {‘Name’: [‘Alice’, ‘Bob’, ‘Charlie’],
‘Age’: [25, 30, 22]}
df = pd.DataFrame(data)
young_people = df[df[‘Age’] < 30]
print(young_people)
import pandas as pd
data = {‘Name’: [‘Alice’, ‘Bob’, ‘Charlie’, ‘Alice’, ‘Bob’],
‘Age’: [25, 30, 22, 28, 32]}
df = pd.DataFrame(data)
grouped = df.groupby(‘Name’)[‘Age’].mean()
print(grouped)
import pandas as pd
data = {‘Name’: [‘Alice’, ‘Bob’, ‘Charlie’],
‘Age’: [25, 30, 22]}
df = pd.DataFrame(data)
df[‘Gender’] = [‘Female’, ‘Male’, ‘Male’]
print(df)
import pandas as pd
import numpy as np
data = {‘Name’: [‘Alice’, ‘Bob’, np.nan],
‘Age’: [25, np.nan, 22]}
df = pd.DataFrame(data)
cleaned_df = df.dropna()
print(cleaned_df)
import pandas as pd
import numpy as np
data = {‘Name’: [‘Alice’, ‘Bob’, np.nan],
‘Age’: [25, np.nan, 22]}
df = pd.DataFrame(data)
filled_df = df.fillna({‘Name’: ‘Unknown’, ‘Age’: 0})
print(filled_df)
import pandas as pd
data = {‘Name’: [‘Alice’, ‘Bob’, ‘Charlie’],
‘Age’: [25, 30, 22]}
df = pd.DataFrame(data)
sorted_df = df.sort_values(by=’Age’, ascending=False)
print(sorted_df)
import pandas as pd
data = {‘Name’: [‘Alice’, ‘Bob’, ‘Charlie’, ‘Alice’, ‘Bob’],
‘Age’: [25, 30, 22, 28, 32]}
df = pd.DataFrame(data)
aggregated = df.groupby(‘Name’)[‘Age’].agg([‘mean’, ‘min’, ‘max’])
print(aggregated)