Create a DataFrame from CSV file in Python

Create a DataFrame from CSV file in Python

Create a DataFrame from CSV file. Which contains Book_no,Book_name,Price,Author. Performs Print values of book name, Display Book Name and Author, Display details of Book named ‘Let us C’, Display details of Book at location 3rd.

Crate books.csv

Book_no,Book_name,Price,Author
1,Let us C,250,Yashavant Kanetkar
2,Python Basics,300,Guido van Rossum
3,Data Structures,400,Mark Allen Weiss
4,Computer Networks,350,Andrew Tanenbaum

import pandas as pd

df = pd.read_csv(“books.csv”)

1. Print values of Book Name

print(“\nBook Names:”)
print(df[“Book_name”])

2. Display Book Name and Author

print(“\nBook Name and Author:”)
print(df[[“Book_name”, “Author”]])

3. Display details of Book named ‘Let us C’

print(“\nDetails of ‘Let us C’:”)
print(df[df[“Book_name”] == “Let us C”])

4. Display details of Book at 3rd location

print(“\nDetails of Book at 3rd location:”)
print(df.iloc[2])