Created
April 26, 2018 19:25
-
-
Save raprasad/07ef09cc2427815a1384a4fd965c1105 to your computer and use it in GitHub Desktop.
get dataframe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_dataframe(input_file, start_idx=0, num_rows=100, delimiter=None, is_excel=False): | |
"""Retrieve a pandas dataframe based on format""" | |
try: | |
if is_excel: | |
dataframe = pd.read_excel(input_file) # add nrows, skiprows + lineterminator, if needed | |
else: | |
dataframe = pd.read_csv(input_file, | |
delimiter=delimiter) # add nrows, skiprows + lineterminator, if needed | |
return ok_resp(dataframe) | |
except pd.errors.ParserError as err_obj: | |
err_msg = ('Failed to load csv file (pandas ParserError).' | |
'\n- File: %s' | |
'\n- %s') % \ | |
(input_file, err_obj) | |
return err_resp(err_msg) | |
except PermissionError as err_obj: | |
err_msg = ('No read prermission on this file:' | |
'\n- File: %s' | |
'\n- %s') % \ | |
(input_file, err_obj) | |
return err_resp(err_msg) | |
except Exception as err_obj: | |
err_msg = ('Failed to load file.' | |
'\n- File: %s' | |
'\n- %s') % \ | |
(input_file, err_obj) | |
return err_resp(err_msg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment