FileReader
FileReader
__init__(path: str, has_units: bool = False, index: Optional[str] = None, usecols: List[str] = None, filter_by: Dict[str, List[str]] = {})
Initialize a FileReader instance to read data from a file.
Parameters: path (str, os.PathLike): The path to the file. has_units (bool): Indicates if the file has units (default is False). index (str, optional): The name of the index column (default is None). usecols (List[str], optional): A list of column names to read (default is None). filter_by (Dict[str, List[str]]): A dictionary of column names and values (list of str) to filter by (default is an empty dictionary).
Raises: FileNotFoundError: If the specified file does not exist. TypeError: If there's an issue reading the file or if the resulting DataFrame is not of type pandas.DataFrame.
Attributes: df (pd.DataFrame): a dataframe containing the data from the file.
Note: - When has_units is True, the file is expected to have units information, and the units_file attribute will be set. - The read_csv method is called with different parameters to attempt reading the file with various delimiters and encodings. - If an index column is specified, it will be used as the index in the DataFrame.
Example: FileReader('plants.plt', has_units = False, index = 'name', usecols=['name', 'plnt_typ', 'gro_trig'], filter_by={'plnt_typ': 'perennial'})
overwrite_file() -> None
Overwrite the original file with the DataFrame.
This method checks the file extension and calls the appropriate storage method (_store_csv or _store_text).
Returns: None