10 exercices in pandas with solutions
- User
10 exercices in pandas with solutions
Assistant
- Filtering rows by a condition:
import pandas as pd # Example dataset data = {'A': [1, 2, 3, 4, 5], 'B': [6, 7, 8, 9, 10]} df = pd.DataFrame(data) # Filter rows where column A is greater than 3 filtered_df = df[df['A'] > 3] print(filtered_df)- Selecting specific columns:
# Example dataset data = {'A': [1, 2, 3, 4, 5], 'B': [6, 7, 8, 9, 10], 'C': [11, 12, 13, 14, 15]} df = pd.DataFrame(data) # Select columns A and C selected_cols = ['A', 'C'] selected_df = df[selected_cols] print(selected_df)- Renaming a column:
# Example dataset data = {'old_name': [1, 2, 3, 4, 5], 'B': [6, 7, 8, 9, 10]} df = pd.DataFrame(data) # Rename column old_name to new_name df.rename(columns={'old_name': 'new_name'}, inplace=True) print(df)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.