read_files.py

read_file()

EzPyZ.tools.read_file(filename: str, return_pandas_df=False)

Reads the provided Excel or CSV data file. Returns a pandas DataFrame object if return_pandas_df is True, or a dictionary where the keys are column titles and the values are lists of associated values (in order) otherwise.

Parameters
  • filename (str) – The qualified path to the data file to read.

  • return_pandas_df – (optional) Boolean. Whether the data should be returned as a pandas.DataFrame. Defaults to False.

Returns

A formatted version of the data in filename.

Return type

pandas.DataFrame or Dict[str, List[Any]]]

Usage:

>>> import EzPyZ as ez
>>> data = ez.tools.read_file("bmi_data.csv")

is_excel()

EzPyZ.tools.is_excel(filename)

Returns True if the file provided in filename is a valid Excel file, and False otherwise.

Parameters

filename (str) – The qualified name of the file to be checked.

Returns

Boolean. Whether filename is a valid Excel file.

Return type

bool

Usage:

>>> import EzPyZ as ez
>>> ez.tools.read_files.is_excel("bmi_data.xlsx")
True