Home > Software engineering >  user defined function in python to read csv file
user defined function in python to read csv file

Time:10-25

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')

CodePudding user response:

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)
  • Related