Abbas Khan
Abbas Khan

Reputation: 15

user defined function in python to read csv file

Reads in a dataset using pandas.

Parameters
----------
file_path : string containing path to a file

Returns
-------
Pandas DataFrame with data read in from the file path
'''

I have defined the following UDF but it doesnt work.

def read_data(file_path): pandas.read_csv('file_path')

Upvotes: 0

Views: 365

Answers (1)

Jason Baker
Jason Baker

Reputation: 3698

Looks like you are missing the return and the variable shouldn't have quotes

import pandas as pd


def read_data(file_path: str) -> pd.DataFrame: 
    return pd.read_csv(file_path)

Upvotes: 1

Related Questions