I need to merge three datasets so that I can create a custom function that would do the following: Create a function called theme_by_year that takes as input a year (as an integer) and shows the theme ids and theme names (listed in order by theme id) that were in sets that year. The column names must be id and name_themes (to differentiate between the name of a theme and the name of a set) in that order. The index should be reset and go from 0 to n-1. Each theme should only be listed once even if it appeared in more than one set from that year -- duplicate themes should be based on theme id and not name since there are some themes with the same name but with a different id. Hint: It will help if you were to think about merging appropriate DataFrames to help you get this answer. The desired output should look like this: theme_by_year(1960) Output: id    name_themes 0    371    Supplemental 1    497    Books 2    513    Classic

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question

I need to merge three datasets so that I can create a custom function that would do the following:

Create a function called theme_by_year that takes as input a year (as an integer) and shows the theme ids and theme names (listed in order by theme id) that were in sets that year.

The column names must be id and name_themes (to differentiate between the name of a theme and the name of a set) in that order.

The index should be reset and go from 0 to n-1.

Each theme should only be listed once even if it appeared in more than one set from that year -- duplicate themes should be based on theme id and not name since there are some themes with the same name but with a different id.

Hint: It will help if you were to think about merging appropriate DataFrames to help you get this answer.

The desired output should look like this:

theme_by_year(1960)

Output:

id    name_themes
0    371    Supplemental
1    497    Books
2    513    Classic

Here's what I tried, but I did not get the desired output:

 

Here's what I tried, but I did not get the desired output:
merged_data = inventory_sets.merge(sets, on="set_num"). merge (themes,
on="id")
def theme_by_year(year):
# Filter for the desired year
year_data = merged_data[merged_data["year"] == year]
# Remove duplicate themes based on theme id
unique_themes = year_data.drop_duplicates (subset="id")[["id",
"name"]]
# Rename columns to id and name_themes
unique_themes = unique_themes.rename (columns={'theme_id':
'id', "name": "name_themes"})
# Reset index to 0 to n-1
unique_themes = unique_themes.reset_index (drop=True)
return unique_themes [["id", "name_themes"]]
Transcribed Image Text:Here's what I tried, but I did not get the desired output: merged_data = inventory_sets.merge(sets, on="set_num"). merge (themes, on="id") def theme_by_year(year): # Filter for the desired year year_data = merged_data[merged_data["year"] == year] # Remove duplicate themes based on theme id unique_themes = year_data.drop_duplicates (subset="id")[["id", "name"]] # Rename columns to id and name_themes unique_themes = unique_themes.rename (columns={'theme_id': 'id', "name": "name_themes"}) # Reset index to 0 to n-1 unique_themes = unique_themes.reset_index (drop=True) return unique_themes [["id", "name_themes"]]
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Query Syntax
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education