Pandas Training Questions
Q1. Write a Python program to create a Pandas DataFrame from a dictionary.
import pandas as pd
data = {'Name': ['Alice', 'Bob', 'Charlie'],
'Age': [25, 30, 35],
'City': ['New York', 'Paris', 'London']}
df = pd.DataFrame(data)
print(df)
# ??? ????? DataFrame ?? ????? ????? ??? ?????? ?????? ????.
Q2. Write a Python program to create a Pandas Series from a list.
import pandas as pd
data = [10, 20, 30, 40]
s = pd.Series(data)
print(s)
# ??? ????? Series ?? ????? ?????? ?????? ??????.
Q3. Write a Python program to read a CSV file and show the first and last 5 rows.
import pandas as pd
df = pd.read_csv('data.csv')
print(df.head())
print(df.tail())
# ????? ??? CSV ? ??? ??? ???? 5 ????.
Q4. Write a Python program to filter rows where Age is greater than 28.
filtered_df = df[df['Age'] > 28]
print(filtered_df)
# ????? ?????? ???? ???? ????? ???? ?? 28.
Q5. Write a Python program to sort a DataFrame by Age in descending order.
df_sorted = df.sort_values(by='Age', ascending=False)
print(df_sorted)
# ????? ???????? ??? ????? ????????.
Pandas Training Questions
Q6. Write a Python program to group data by City and calculate average Age.
df_grouped = df.groupby('City')['Age'].mean()
print(df_grouped)
# ????? ??? ??????? ?? ???? ????? ?????.
Q7. Write a Python program to add a new column to a DataFrame.
df['Salary'] = [50000, 60000, 70000]
print(df)
# ????? ???? ???? 'Salary'.
Q8. Write a Python program to drop the column 'Salary' from a DataFrame.
df = df.drop(columns=['Salary'])
print(df)
# ??? ???? Salary.
Q9. Write a Python program to check for missing values in a DataFrame.
print(df.isnull())
print(df.isnull().sum())
# ?????? ?? ????? ???????? ?????? ?? ?? ????.
Q10. Write a Python program to replace missing values in 'Salary' with the column's mean.
df['Salary'].fillna(df['Salary'].mean(), inplace=True)
# ????? ????? ???????? ?????? ??????.
Q11. Write a Python program to merge two DataFrames on a common column 'ID'.
import pandas as pd
df1 = pd.DataFrame({'ID': [1, 2, 3], 'Name': ['Alice', 'Bob', 'Charlie']})
df2 = pd.DataFrame({'ID': [1, 2, 3], 'Salary': [5000, 6000, 7000]})
merged_df = pd.merge(df1, df2, on='ID')
print(merged_df)
# ??? ?????? ???????? ?????? ??????? ID.
Q12. Write a Python program to remove duplicate rows from a DataFrame.
Pandas Training Questions
df = pd.DataFrame({'A': [1, 2, 2, 3], 'B': [4, 5, 5, 6]})
df = df.drop_duplicates()
print(df)
# ??? ?????? ???????.
Q13. Write a Python program to apply a function to a column.
df = pd.DataFrame({'Name': ['Alice', 'Bob'], 'Age': [25, 30]})
df['Age in 5 years'] = df['Age'].apply(lambda x: x + 5)
print(df)
# ????? ???? ???? ???? ????? ??? 5 ?????.