Dataset Viewer
Auto-converted to Parquet Duplicate
index
int64
0
8.66k
python
stringlengths
74
2.78k
32
results = city.loc[city['Population'].idxmax(), ['Official_Name', 'Status']] print(results)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The city with the largest population is: Official Name:icity Status:
148
result = weather.groupby('zip_code').mean()['mean_sea_level_pressure_inches'].idxmin() print(result)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The zip code with the lowest average mean sea level pressure is:[CODE_START_TOK] print(result)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK]
129
# Use the `city` column to filter the stations # Use the `len` function to count the number of stations stations_in_mountain_view = station[station['city'] == 'Mountain View'].len() print(stations_in_mountain_view)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK]
46
# Use groupby to get the most common type of Status across cities most_common_status = city.groupby('Status').size() print(most_common_status)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The most common type of Status across cities is <insert status here>. This status is represented by <insert percentage here> cities.
98
result = [] for _, row in people.iterrows(): result.append(row['first_name']) result.sort() print(result)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The first names of the people in the dataframe are ['Anna', 'Bob', 'Charlie', 'David'] in alphabetical order.
50
status = city[city['Population'] > 1500 & city['Population'] < 500]['Status'] print(status)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The status shared by cities with population bigger than 1500 and smaller than 500 is: print(status)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK]
244
# First, let's find the oldest actor oldest_actor = actor.iloc[0] # Then, let's find the duration of the oldest actor duration = oldest_actor['Duration'] print(duration)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The duration of the oldest actor is: <oldest_actor_duration>
235
result = actor.shape[0] # Count the number of actors[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided will return the number of actors in the `actor` DataFrame. The `shape[0]` attribute returns the number of rows in the DataFrame. Therefore, this code successfully answers the question. If you have any...
234
result = actor.shape[0] print(result)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided above uses the `shape` attribute of the `actor` dataframe to get the number of actors. The `shape[0]` returns the number of rows in the dataframe, which is the number of actors in this case. Therefore, the number of ...
231
# Use the `Publication_Date` column to get a distinct count distinct_dates = publication['Publication_Date'].nunique() print(distinct_dates)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The number of distinct publication dates is: <number of distinct dates> This is the number of unique dates found in the 'Publication_Date...
47
# Use the groupby function to count the number of occurrences for each status status_counts = city.groupby('Status').size() # Get the most common status most_common_status = status_counts.idxmax() # Print the most common status print(most_common_status)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The most common status ...
245
# Use the max function to find the actor with the greatest age max_age = actor['age'].max() max_duration = actor.loc[actor['age'] == max_age]['Duration'].iloc[0] print(max_duration)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The duration of the actor with the greatest age is: <actor_duration>. This is based on the infor...
39
# Use the Foreign Key to find the city with the most competitions city_with_most_competitions = city[city['City_ID'] == farm_competition['Host_city_ID'].max()] # Print the status of the city print(city_with_most_competitions['Status'])[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The status of the city that has hosted the...
57
# Use the Foreign key constraint to find the course with the most students course_with_most_students = student_course_registrations.groupby('course_id')['student_id'].idxmax() course_name = courses.loc[course_with_most_students, 'course_name'] print(course_name)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The course with ...
131
result = [] # Use the foreign key to map stations to their respective status data station_status = pd.merge(station, status, on='id') # Filter for stations with 7 bikes available seven_bikes = station_status[station_status['bikes_available'] == 7] # Return the unique names of these stations result = seven_bikes['na...
173
# Use the `sort_values` function to sort the stations by latitude stations = station.sort_values('lat') # Get the station with the lowest latitude lowest_latitude_station = stations.head(1) print("Name: ", lowest_latitude_station['name']) print("Latitude: ", lowest_latitude_station['lat']) print("City: ", lowest_lat...
28
# UseGroupby to get the unique statuses statuses = city.groupby('Status') print(statuses.nunique())[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided above groups the cities by their status and then calculates the number of unique statuses. Unique statuses are considered as different regions, and the nu...
124
# Use the pandas function to filter the data filtered_data = weather[weather['date'].str.startswith('8')] # Calculate the average mean temperature for all dates that start with '8' average_mean_temperature = filtered_data['mean_temperature_f'].mean() print(average_mean_temperature)[/CODE_END_TOK][RESULT_TOK][/RESULT...
213
# Use the .shape attribute to get the number of books book_count = book.shape[0] print(book_count)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided will output the number of books in the `book` DataFrame. This is achieved by using the `.shape` attribute of the DataFrame, which returns the number of row...
78
# Use the foreign key to get the student with the most registrations student_with_most_registrations = student_course_registrations.groupby('student_id').size().idxmax() # Use the student id to get the student details student_details = students.loc[student_with_most_registrations] print(student_details)[/CODE_END_TO...
55
# Create a boolean mask for "Village" status status_mask = city['Status'] != 'Village' # Apply the mask to get the cities without "Village" status cities = city[status_mask] # Get the census rankings of these cities census_rankings = cities['Census_Ranking'] print(census_rankings)[/CODE_END_TOK][RESULT_TOK][/RESULT...
233
result = publication[publication['Publisher'].isin(['Person', 'Wiley'])].sort_values('Price', ascending=True) print(result)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided sorts the publications by their price in ascending order and then filters them to include only those where the publisher is either...
240
result = [] for index, row in actor.iterrows(): if row['age'] != 20: result.append(row['Name']) print(result)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided above iterates through each row in the `actor` dataframe. If the `age` column of a row does not equal 20, the `Name` column of that ...
214
result = book['Writer'].sort_values(ascending=True).tolist() print(result)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided will sort the writers of the books in ascending alphabetical order. The `sort_values` function is used to sort the 'Writer' column in the `book` DataFrame. The `ascending=True` ar...
24
# Calculate the total number of horses total_horses = farm['Total_Horses'].sum() # Calculate the number of working horses working_horses = farm['Working_Horses'].sum() # Calculate the average number of working horses average_working_horses = working_horses / total_horses print(average_working_horses)[/CODE_END_TOK]...
241
# Use the column 'age' to filter the dataframe old_actors = actor[actor['age'] != 20] # Use the column 'Name' to get the names of the actors actor_names = old_actors['Name'] # Print the names of the actors print(actor_names)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided above will filter the dataf...
125
result = trip.groupby('bike_id')['id'].count() print(result)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The code above groups the trips by the unique bikes and then counts the number of trips for each bike. The result is a Series where the index is the unique bikes and the value is the count of trips for each bike. To g...
239
result = actor[['Character', 'Duration']] print(result)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] This Python code will return the characters and durations for each actor in the `actor` dataframe. The `result` variable will contain a new dataframe that has two columns: 'Character' and 'Duration'. Each row will represent...
181
First, let's calculate the average mean visibility for each zip code:[CODE_START_TOK] avg_mean_visibility = weather.groupby('zip_code')['mean_visibility_miles'].mean() ```[RESULT_TOK][/RESULT_TOK] Next, we'll find the zip code with the lowest average mean visibility:[CODE_START_TOK] lowest_avg_mean_visibility = avg_me...
71
# Use the foreign key to get the course ids for the student course_ids = student_course_attendance.loc[student_course_attendance['student_id'] == 171]['course_id'] # Use the course ids to get the course names courses = courses.loc[courses['course_id'].isin(course_ids)] # Count the number of courses the student atten...
227
# Use the `groupby` method to group the data by 'Publication_Date' and calculate the `size` of each group publication_dates = publication.groupby('Publication_Date')['Publication_ID'].size() # Use the `idxmax` method to find the index of the max size max_date = publication_dates.idxmax() # Print the max publication ...
29
# Use the `Status` column to generate a unique list of statuses statuses = city['Status'].unique() print(statuses)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided above will output the unique list of statuses in the 'Status' column of the city dataframe. If there are no duplicates in the 'Status' colu...
48
# Use the city dataframe to filter for cities that have not held any competition cities_without_competition = city[city['Census_Ranking'] == 'Non-metropolitan area'] # Print the official names of the cities official_names = cities_without_competition['Official_Name'] print(official_names)[/CODE_END_TOK][RESULT_TOK][/...
1
# Use the pd function to generate a sorted dataframe sorted_heads = head.sort_values('age') # Use the .head(n) function to get the first n rows first_rows = sorted_heads.head(10) # Print the dataframe print(first_rows)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The code above sorts the data by the 'age' column and then...
16
[CODE_START_TOK] # Use the `Farm_ID` column to find the unique farms farms = farm['Farm_ID'].unique() print(len(farms))[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided above will count the number of unique farms in the `farm` DataFrame. The `Farm_ID` column is used to identify each farm, so by finding ...
119
result = trip.sort_values('duration').head(1)['id'] ```[RESULT_TOK][/RESULT_TOK] The code above sorts the trips in ascending order of their duration and then fetches the first (i.e., shortest) trip. The 'id' column is then extracted from this row to obtain the trip ID. Please note that since the 'duration' column is...
126
from pandas.util import unique_vals # Get all unique bike ids bike_ids = unique_vals(trip['bike_id']) print(len(bike_ids))[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided above uses the `pandas.util.unique_vals` function to find all unique bike ids in the `trip` DataFrame. The `len` function is then ...
97
The first names of the people in alphabetical order can be obtained by sorting the `first_name` column in ascending order. Here is the Python code to do this:[CODE_START_TOK] first_names = people['first_name'].sort_values(ascending=True) print(first_names)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provid...
112
result = [] for index, row in station.iterrows(): if row['lat'] < 37.5: result.append(row['name']) print(result)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The code above generates a list of all station names with a latitude smaller than 37.5. The `iterrows()` function is used to iterate over each row in the ...
143
result = station[station['installation_date'].str.contains('December')] result = result[result['bikes_available'] > 14] print(result[['name', 'id']])[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided above will filter the stations that were installed in December and have more than 14 bikes available. T...
88
result = student_course_attendance.where(student_course_attendance['course_id'] == 301).drop_duplicates('student_id') print(result)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided above will return the student IDs of those who registered for course 301. The `where` method is used to filter the data to...
110
result = weather[weather['max_temperature_f'] > 85]['date'].values print(result)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided above will filter the dates in the 'weather' DataFrame where the maximum temperature is higher than 85 degrees fahrenheit. The filtered dates are then stored in the 'result'...
117
# Filter the stations by city stations_in_san_jose = station[station['city'] == 'San Jose'] # Calculate the average latitude and longitude average_latitude = stations_in_san_jose['lat'].mean() average_longitude = stations_in_san_jose['long'].mean() print(f'The average latitude is {average_latitude} and the average l...
232
result = publication['Publication_Date'].nunique() print(result)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided above will return the number of distinct publication dates in our record. Since we don't have any actual data, the `publication` DataFrame is empty, so the result will be 0. If we had actua...
30
# Get the population of each city population = city['Population'] # Sort the cities by population in descending order sorted_cities = city.sort_values(by='Population', ascending=False) # Print the official names of the cities official_names = sorted_cities['Official_Name'] print(official_names)[/CODE_END_TOK][RESULT...
49
# Use the city dataframe to find cities that have not hosted a farm competition cities_without_competition = city[city.Host_city_ID.isna()] # Get the official names of these cities official_names = cities_without_competition['Official_Name'] print(official_names)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The official ...
38
# Use the foreign key to find the city with the most competitions most_competitive_city = city.loc[farm_competition.groupby('Host_city_ID')['Competition_ID'].idxmax()] print(most_competitive_city['Status'])[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The status of the city that has hosted the greatest number of competiti...
19
result = farm.groupby('Farm_ID')['Total_Horses'].agg(lambda x: x.sort_values()).reset_index() print(result)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided above groups the data by each 'Farm_ID' and then sorts the 'Total_Horses' for each farm in ascending order. The result is a new DataFrame where th...
221
# Use the ``groupby`` function to group the data by 'Book_ID' and then by 'Publication_Date' # Use the ``idxmin`` function to get the index of the minimum 'Price' # This will give us the publication date of the book with the lowest price # result will be a Series where the index is a MultiIndex # The first level of t...
215
# Sort the dataframe by 'Issues' in ascending order sorted_books = book.sort_values('Issues', ascending=True) # Extract the 'Title' column from the sorted dataframe title_list = sorted_books['Title'].tolist() # Print the title list print(title_list)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided ab...
212
# Calculate the average latitude and longitude of all starting stations for the trips start_lat = trip.loc[trip['start_station_id'].isin(station.index), 'lat'].mean() start_long = trip.loc[trip['start_station_id'].isin(station.index), 'long'].mean() print(f'The average latitude of starting stations is {start_lat}') p...
236
# Use the .sort_values() function to sort the 'Name' column in ascending order sorted_names = actor.sort_values('Name') # Print the 'Name' column of the sorted dataframe print(sorted_names['Name'])[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The code above sorts the names of the actors in the 'actor' dataframe in ascendi...
4
result = 0 # Iterate over the department DataFrame for i in range(10, 16): # Filter the DataFrame to get departments with rank between 10 and 15 department_filtered = department[department['Ranking'] == i] # Calculate the average number of employees average_employees = department_filtered['Num_Employee...
183
# Calculate the highest latitude of each station station['highest_lat'] = station.groupby('city').lat.idxmax() # Sort the cities in descending order of highest latitude cities = station.city.unique() cities_sorted = cities[cities.index(station.loc[station['highest_lat'], 'city'])::-1] # Print the cities print(cities...
222
# Use the Foreign Key to join the tables result = publication.loc[publication['Book_ID'].isin(book['Book_ID'])] # Display the title and publication dates print(result[['Title', 'Publication_Date']])[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The above Python code will join the 'publication' and 'book' tables based on th...
105
# Use the Foreign Key constraint to get the students who registered for course statistics registered_students = student_course_registrations[student_course_registrations['course_id'] == courses['course_id'][courses['course_name'] == 'course statistics']] # Sort the students by registration date and get their IDs sort...
211
result = None # Use the Foreign Key constraints to get the starting points of all trips start_points = trip[['start_station_id', 'lat', 'long']] # Calculate the average latitude and longitude avg_lat = start_points['lat'].mean() avg_long = start_points['long'].mean() print(f"The average latitude is {avg_lat} and th...
220
max_price = publication['Price'].max() max_publisher = publication.loc[publication['Price'].idxmax(), 'Publisher'] print(f"The publisher of the publication with the highest price is {max_publisher}")[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided above calculates the maximum price from the 'Price' c...
15
# Use the `str.contains` method to find the headers with the substring 'Ha' ha_headers = head[head['name'].str.contains('Ha')] # Print the ID and name of the headers print(ha_headers[['head_ID', 'name']])[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided will find all the headers whose name contains th...
184
# Get the stations for each city stations_by_city = station.groupby('city') # Get the highest station latitude for each city highest_latitude_by_city = stations_by_city['lat'].idxmax() # Sort the cities by the highest station latitude sorted_cities = highest_latitude_by_city.sort_values(ascending=False) # Print the...
188
result = trip.sort_values('duration').tail(1) # Sort by duration and take the last row print(result)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The code above sorts the trips by their duration in descending order and then selects the last row. This last row will be the trip that lasted the longest. The 'id' column repre...
33
The most straightforward way to answer this question is by finding the city with the most residents. We can do this by sorting the cities by population in descending order and then selecting the first city. Here is the code:[CODE_START_TOK] # Sort the cities by population in descending order sorted_cities = city.sort...
216
result = book[~book['Writer'].isin(['Elaine Lee'])].head(10)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided above generates the titles of the books whose writer is not "Elaine Lee". The `~` symbol in front of the condition is used to negate the condition, so this code will find all books where the wr...
31
# Use the Census Ranking column to order the cities descending by population sorted_cities = city.sort_values('Census_Ranking', ascending=False) # Get the official names of the cities official_names = sorted_cities['Official_Name'] # Print the official names of the cities print(official_names)[/CODE_END_TOK][RESULT_...
243
# Use theForeign key to get the actors and their characters actors = actor.merge(character, on='Actor_ID') # Sort the actors by age descending sorted_actors = actors.sort_values('age', ascending=False) # Get the characters for the sorted actors characters = sorted_actors['Character'] print(characters)[/CODE_END_TOK...
118
# Use the `city` column to filter the data san_jose_stations = station[station['city'] == 'San Jose'] # Calculate the average latitude and longitude avg_lat = san_jose_stations['lat'].mean() avg_long = san_jose_stations['long'].mean() print(f'The average latitude in San Jose is {avg_lat}') print(f'The average longit...
154
max_temp_station_zip = weather.loc[weather['max_temperature_f'] == weather['max_temperature_f'].max()]['zip_code'].values[0] max_temp_date = weather.loc[weather['max_temperature_f'] == weather['max_temperature_f'].max()]['date'].values[0] print(f"The zip code with the max temperature is {max_temp_station_zip} on {max_...
247
# Use the fancy pandas syntax to filter the dataframe filtered_df = musical[musical['Nominee'] == 'Bob Fosse'] # Print the names of the musicals result = filtered_df['Name'].values print(result)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided above will filter the `musical` dataframe to include only ...
174
# Use the `max` function to find the station with the highest latitude south_station = station.loc[station['lat'].idxmax()] print("Name:", south_station['name']) print("Latitude:", south_station['lat']) print("City:", south_station['city'])[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The code above finds the station with...
87
# Use the `course_id` column to filter for students who registered course 301 students_in_301 = student_course_attendance[student_course_attendance.course_id == 301] # Use the `student_id` column to get the unique student IDs students_in_301_ids = students_in_301.student_id.unique() # Print the students' IDs print(s...
264
# Use the `groupby` function to group the dataframe by 'Result' and `size` to count the number of occurrences in each group. # The `sort_values` function is used to sort the grouped dataframe by 'size' in descending order. # Finally, we use the `head` function to get the top 10 results. results = musical.groupby('Re...
21
# Use the `Theme` column to filter the competitions alien_competitions = farm_competition[farm_competition['Theme'] != 'Aliens'] # Use the `Hosts` column to get the hosts of these competitions hosts = alien_competitions['Hosts'] # Print the hosts print(hosts)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code p...
77
# Join the two dataframes on student_id student_course_registrations_joined = pd.merge(students, student_course_registrations, on='student_id') # Group by 'student_id' and find the maximum number of courses registered max_courses_registered_per_student = student_course_registrations_joined.groupby('student_id').max()...
254
# Use the Foreign key constraints to join the 'actor' and 'musical' dataframes joined_df = pd.merge(actor, musical, on='Musical_ID') # Sort the dataframe by 'Year' in descending order sorted_df = joined_df.sort_values(by='Year', ascending=False) # Print the 'Name' column of the sorted dataframe result = sorted_df['N...
138
result = 0 for index, row in weather.iterrows(): if (row['mean_humidity'] > 50) and (row['mean_visibility_miles'] > 8): result += 1 print(result)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided above iterates over each row in the `weather` dataframe. For each row, it checks if the mean hu...
111
result = [] for _, row in station.iterrows(): if row['lat'] < 37.5: result.append(row['name']) print(result)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided above generates a list of station names that have a latitude lower than 37.5. The code iterates through each row in the station data...
196
# Use the pandas function to filter the data filtered_data = weather[weather['max_dew_point_f'] < 70] # Use the pandas function to group and aggregate the data grouped_data = filtered_data.groupby('zip_code')['max_dew_point_f'].agg(max) # Use the pandas function to get the unique zip codes unique_zip_codes = grouped...
69
# Use the course_id column to filter the students who attend English course english_students = student_course_attendance[student_course_attendance['course_id'] == 1] # Count the number of students who attend English course result = english_students.shape[0] print(result)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The P...
127
# Use the `city` column to create a distinct set of cities distinct_cities = station.city.drop_duplicates() result = len(distinct_cities)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided above will produce the number of distinct cities the stations are located at. The `drop_duplicates()` function is us...
150
# Calculate the average bike availability for stations not in Palo Alto non_palo_alto_stations = station[~station['city'].isin(['Palo Alto'])].dropna() bikes_available = non_palo_alto_stations['bikes_available'] docks_available = non_palo_alto_stations['docks_available'] # Calculate the average bike availability ave...
182
result = weather.groupby('zip_code')['mean_visibility_miles'].mean() below_10_zip_codes = result[result < 10].keys() print(below_10_zip_codes)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The provided Python code groups the weather data by zip code and then calculates the mean visibility for each zip code. It then filters ...
203
result = pd.merge(station, status, on='id') result = result[result['bikes_available'] > 12] print('Station ID:', result['id'], '\nStation Name:', result['name'])[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided above first merges the 'station' and 'status' dataframes on the 'id' column. This creates a ...
94
result = [] # Use the foreign key relation to get the address_id # Then use the address_id to get the city students['address_id'] = addresses.merge(students, on='student_id')['address_id'] result = students.groupby('city').size() print(result)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided above ge...
104
# Use the dataframes to create a new dataframe that has students who registered but did not attend any course students_registered = student_course_registrations.groupby('student_id').size() students_attended = student_course_attendance.groupby('student_id').size() students_not_attended = students_registered[students_...
237
# Convert the 'Name' column to string type actor['Name'] = actor['Name'].astype(str) # Sort the DataFrame by 'Name' in ascending order sorted_actor = actor.sort_values('Name') # Print the 'Name' column of the sorted DataFrame actor_names = sorted_actor['Name'].tolist() print(actor_names)[/CODE_END_TOK][RESULT_TOK][/...
68
# First, we need to find out which students have recently registered for courses recent_registrations = student_course_registrations[student_course_registrations['registration_date'] == max(student_course_registrations['registration_date'])] # Then, we need to find out the details of these students recent_students = ...
0
# Use the pandas function to filter the dataframe filtered_data = head[head['age'] > 56] # Count the number of rows in the filtered dataframe result = filtered_data.shape[0] print(result)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code above generates a new dataframe that contains only the rows from the `hea...
73
# Use the `email_address` column in the `people` dataframe to find the id of the candidate candidate_id = people.loc[people['email_address'] == 'stanley.monahan@example.org', 'person_id'].values[0] print(candidate_id)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided will find the candidate ID of the pe...
133
result = trip.sort_values(by='start_date', ascending=False) # Sort by start_date in descending order result = result.head(1) # Get the first station (i.e., the station with the most trips) print(f"The start station with the most trips was {result['start_station_name'].iloc[0]}, with id {result['start_station_id'].il...
122
# Use the WHERE clause to filter the data for the specific bike id filtered_trips = trip.where(trip['bike_id'] == 636) # Calculate the total duration and the maximum duration total_duration = filtered_trips['duration'].sum() max_duration = filtered_trips['duration'].max() # Print the results print(f"Total duration: ...
149
# Get the stations that are not located in Palo Alto palo_alto = station[station['city'] == 'Palo Alto'] non_palo_alto = station[~station['city'].isin(palo_alto['city'])] # Calculate the average bike availability bike_availability = status[status['station_id'].isin(non_palo_alto['id'])].groupby('station_id')['bikes_a...
35
result = city.merge(farm_competition, on='City_ID') # Merge city and farm_competition dataframes on 'City_ID' result = result[['Year', 'Official_Name']] # Select years and official names print(result)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code above will produce the years and official names of the citie...
84
result = [] for index, row in candidate_assessments.iterrows(): if row['asessment_outcome_code'] == 'Pass': result.append(row['candidate_id']) print(result)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided above will output the candidate IDs of those who have an outcome code of 'Pass'. Sin...
177
city_with_station_count = station.groupby('city')['dock_count'].agg(lambda x: len(x[x >= 15])) result = city_with_station_count[city_with_station_count >= 1].index # get cities with at least 1 station print(result)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided above groups the stations by city and ...
72
# Use the foreign key to get the student's courses student_courses = courses[courses.student_id == 171] # Count the number of courses the student actually attends attended_courses = student_courses[student_courses.date_of_attendance != ''] print(attended_courses.shape[0])[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The ...
18
# Use the pandas function to sort the data in ascending order sorted_data = farm.sort_values('Total_Horses', ascending=True) # Print the Farm_ID and Total_Horses columns result = sorted_data[['Farm_ID', 'Total_Horses']] print(result)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided above sorts the to...
10
result = management.loc[management.temporary_acting == 'Y'].shape[0] print(result)[/CODE_END_TOK][RESULT_TOK][/RESULT_TOK] The Python code provided above will return the number of rows in the `management` dataframe where the `temporary_acting` column is 'Y'. This is because `loc` is used to filter the dataframe based ...
26
# Initialize variables max_cows = None min_cows = None # Iterate over each farm for index, row in farm.iterrows(): if max_cows is None or row['Cows'] > max_cows: max_cows = row['Cows'] if min_cows is None or row['Cows'] < min_cows: min_cows = row['Cows'] print(f"Maximum number of cows: {max_c...
58
# First, let's find out the number of courses each student registered student_courses = student_course_registrations.groupby('student_id').size() # Now, we'll find the student_id of the students who registered the least number of courses least_courses_students = student_courses.idxmin() print(least_courses_students)...
249
# Use the pandas function to filter the data non_tony_awards = musical[musical['Award'] != 'Tony Award'] # Use the pandas function to group the data and get the count nominees = non_tony_awards.groupby('Nominee').size() # Use the pandas function to get the top 5 nominees top_5_nominees = nominees.head(5) # Print th...
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
7