Create a Python program that opens and reads a csv file. Display csv file in legible format. Include the program as a function.
Python program done in Jupyter notebook:
Code:
import pandas as pd
def my_function():
bp = pd.read_csv("blood_pressure.csv")
print(bp.head())
my_function()
Excel Sheet:
Output:
Here we have used pandas library inorder to open and read a csv file.
A sample csv file (blood_pressure.csv) is taken. It is present in the same working directory of my Jupyter notebook workspace.
Otherwise you have to mention the whole path inside read_csv() function.( like read_csv("/path") )
head() retrieves the first 5 rows of csv file.
Get Answers For Free
Most questions answered within 1 hours.