Duplicate Question
The question on this page has been marked as a duplicate question.
Original Question
Q17: Create a function called sets_from_minifig that takes as input a minifig number (as a string) and returns a list of sets a...Asked by Ccolloh
**Q17:**
- Create a function called `sets_from_minifig` that takes as input a minifig number (as a string) and returns a list of sets a minifig has appeared in.
- Return a DataFrame (sorted by `set_num` and then by `version`) with the following columns: `set_num`, `version`,`name_sets`, `fig_num`, `fig_name`.
- The index should go from 0 to n-1.
**Code Check:** Call your `sets_from_minifig()` function on one of the Lego Friends minifigs, Andrea, who has figure number: `fig-001039`. Your function should return a DataFrame that contains the following sets:
- Andrea on the Beach
- Birthday Party
- City Park Cafe
- Create a function called `sets_from_minifig` that takes as input a minifig number (as a string) and returns a list of sets a minifig has appeared in.
- Return a DataFrame (sorted by `set_num` and then by `version`) with the following columns: `set_num`, `version`,`name_sets`, `fig_num`, `fig_name`.
- The index should go from 0 to n-1.
**Code Check:** Call your `sets_from_minifig()` function on one of the Lego Friends minifigs, Andrea, who has figure number: `fig-001039`. Your function should return a DataFrame that contains the following sets:
- Andrea on the Beach
- Birthday Party
- City Park Cafe
Answers
There are no human answers yet.
Answered by
GPT 3.5
To solve this task, I will perform the following steps:
1. Create an empty list called `sets` to store the sets a minifig has appeared in.
2. Iterate over each row in the `sets` DataFrame.
3. Check if the figure number in the current row matches the input minifig number.
4. If there is a match, append the set name to the `sets` list.
5. Create a new DataFrame called `result` using the `sets` list.
6. Sort the `result` DataFrame first by `set_num` and then by `version`.
7. Reset the index of the `result` DataFrame.
8. Return the `result` DataFrame.
```python
def sets_from_minifig(minifig_num):
sets = []
for _, row in sets.iterrows():
if row['fig_num'] == minifig_num:
sets.append(row['name_sets'])
result = pd.DataFrame(sets, columns=['set_num', 'version', 'name_sets', 'fig_num', 'fig_name'])
result.sort_values(['set_num', 'version'], inplace=True)
result.reset_index(drop=True, inplace=True)
return result
# Call the function on the 'fig-001039' minifig
minifig_sets = sets_from_minifig('fig-001039')
minifig_sets
```
**Note:** Make sure to replace `sets` with the actual DataFrame variable name in your code.
1. Create an empty list called `sets` to store the sets a minifig has appeared in.
2. Iterate over each row in the `sets` DataFrame.
3. Check if the figure number in the current row matches the input minifig number.
4. If there is a match, append the set name to the `sets` list.
5. Create a new DataFrame called `result` using the `sets` list.
6. Sort the `result` DataFrame first by `set_num` and then by `version`.
7. Reset the index of the `result` DataFrame.
8. Return the `result` DataFrame.
```python
def sets_from_minifig(minifig_num):
sets = []
for _, row in sets.iterrows():
if row['fig_num'] == minifig_num:
sets.append(row['name_sets'])
result = pd.DataFrame(sets, columns=['set_num', 'version', 'name_sets', 'fig_num', 'fig_name'])
result.sort_values(['set_num', 'version'], inplace=True)
result.reset_index(drop=True, inplace=True)
return result
# Call the function on the 'fig-001039' minifig
minifig_sets = sets_from_minifig('fig-001039')
minifig_sets
```
**Note:** Make sure to replace `sets` with the actual DataFrame variable name in your code.
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.