Book Details Management using Pandas DataFrame
Pandas
Easy • 0 votes
📝 Question
Create a DataFrame from CSV file which contains following values.
Book_no, Book_name, Price, Author
Perform following operations on it:
1. Print the values of book name.
2. Display book name and author.
3. Display the details of book named 'Let us C'.
4. Display the details of book at location 3rd.
✅ Solution:
CSV file (book.csv)
Book_no,Book_name,Price,Author
1,Let us C,350,Yashavant Kanetkar
2,Python Basics,450,Guido van Rossum
3,Java Complete,500,James Gosling
4,C++ Primer,550,Bjarne Stroustrup
=======================================================================================
import pandas as pd
# Create DataFrame from CSV file
df = pd.read_csv("books.csv")
# 1. Print the values of book name
print("1. Book Names:")
print(df["Book_name"])
# 2. Display book name and author
print("\n2. Book Name and Author:")
print(df[["Book_name", "Author"]])
# 3. Display the details of book named 'Let us C'
print("\n3. Details of book 'Let us C':")
print(df[df["Book_name"] == "Let us C"])
# 4. Display the details of book at 3rd location
print("\n4. Details of book at 3rd location:")
print(df.iloc[2])