bulum.io.csv_io module
Functions for reading CSVs, particularly time-series CSVs.
- read_ts_csv(filename: str | PathLike, date_format=None, df=None, colprefix=None, allow_nonnumeric=False, assert_date=True, **kwargs) TimeseriesDataframe
Reads a daily timeseries csv into a DataFrame, and sets the index to string dates in the “%Y-%m-%d” format. The method assumes the first column are dates.
- Parameters:
filename (str or PathLike) – Path to the CSV file to read.
date_format (str, optional) – defaults to “%d/%m/%Y” as per Fors. Other common formats include “%Y-%m-%d”, “%Y/%m/%d”.
df (pd.DataFrame, optional) – If provided, the reader will append columns to this dataframe. Defaults to None.
colprefix (str, optional) – If provided, the reader will prepend this to column name. Defaults to None.
allow_nonnumeric (bool, optional) – If False, raises if any column is not numeric. Default is False.
assert_date (bool, optional) – If True, asserts the date index conforms to
"%Y-%m-%d". Default is True.
- Return type:
utils.TimeseriesDataframe
- Raises:
TypeError – If a column is not numeric and
allow_nonnumericis False.ValueError – If the new date range does not overlap with
df.
- write_ts_csv(df: DataFrame, filename: str, *args, **kwargs) None
Write a dataframe to CSV via
pandas.DataFrame.to_csv().- Parameters:
df (pd.DataFrame) – DataFrame to write.
filename (str or PathLike) – Path to the output CSV file.
*args – Passed through to
pandas.DataFrame.to_csv().**kwargs – Passed through to
pandas.DataFrame.to_csv().