Interview Query

Book Availability Update

Start Timer

0:00:00

Upvote
5
Downvote
Save question
Mark as completed
View comments (5)
Next question

As a Python-proficient librarian, you’re building a system to check the availability of book copies more efficiently.

Write a function update_availability to update the copies_available value for a specific book_id in your dataframe and return the updated dataframe.

Note: If you can’t find the book_id, return the original dataframe without any changes.

Example:

Input:

input_df

book_id book_title copies_available
0 Moby Dick 5
1 1984 7
2 To Kill a Mockingbird 3
3 The Great Gatsby 2
4 Pride and Prejudice 10

Output:

update_availability(book_id=3, copies=8, df_books=input_df) -> 
book_id book_title copies_available
0 Moby Dick 5
1 1984 7
2 To Kill a Mockingbird 3
3 The Great Gatsby 8
4 Pride and Prejudice 10
.
.
.
.
.


Comments

Loading comments.