Friday, 31 January 2020

Write a Python method to read from csv file.

# This is tested on Jupytor Notebook.
# Note: Ensure the file name is 'df.csv' which is loaded to your present directory.

# Importing the packages
import os
import pandas as pd

# Read from file
def read_file(file_name): 
    df = pd.read_csv(file_name,error_bad_lines=False)
    return df

# Calling the method
df = read_file('df.csv')

# Display first 5 records
df.head()

# Check size of the data frame
df.shape

No comments:

Post a Comment