def exists_csv(path: str, title: str, ext: str = "csv") -> bool: """Check if the CSV file exists. :param path: the directory path of the CSV file. :param title: the file name of the CSV file. :param ext: the extension of the CSV file (default: 'csv'). :return: indicates if the file exists. """ reader = CsvFile() reader.set(path, title, ext) return reader.exists()
def size_csv(path: str, title: str, ext: str = "csv") -> int: """Check number of lines in the CSV file. :param path: the directory path of the CSV file. :param title: the title of the CSV file. :param ext: the extension of the CSV file. :return: number of lines in the CSV file. """ reader = CsvFile() reader.set(path, title, ext) return reader.size()
def load_csv(path: str, title: str, skip: int = 0, dataframing: bool = True, ext: str = "csv", **kwargs: Any) -> Callable[[List, PandasDataFrame], None]: """Read the CSV file into dataframe or list. :param path: the directory path of the CSV file. :param title: the file name of the CSV file. :param skip: lines to skip before reading or writing. :param dataframing: indicates if the outputs must be saved into dataframe. :param ext: the extension of the CSV file (default: 'csv'). :param kwargs: any other arguments that the selected reader may accept. :return: the read file contents. """ reader = CsvFile() reader.set(path, title, ext) return reader.read(skip, dataframing, **kwargs)
def reset_csv(path: str, title: str, ext: str = "csv"): """Reset the CSV file reader/writer. :param path: the directory path of the CSV file. :param title: the file name of the CSV file. :param ext: the extension of the CSV file (default: 'csv'). """ reader = CsvFile() reader.set(path, title, ext) reader.reset()
def save_csv(path: str, title: str, data: Callable[[List, Dict, PandasDataFrame], None], append: bool = False, ext: str = "csv", **kwargs: Any): """Append to CSV file using dataframe, dictionary or list. :param path: the directory path of the CSV file. :param title: the file name of the CSV file. :param data: the data to write. :param append: indicates if data to be appended to an existing file. :param ext: the extension of the CSV file (default: 'csv'). :param kwargs: any other arguments that the selected writer may accept. """ writer = CsvFile() writer.set(path, title, ext) if append is False: writer.reset() writer.append(data, **kwargs)