Downloaders¶
Utilities to get data in bulk
- calcbench.downloaders.iterate_and_save_pandas(arguments, f, file_name, write_index=True, columns=None, write_mode='w')¶
Apply arguments to a function that returns a DataFrame and save to a .csv file.
- Parameters
arguments (
Sequence
[~T]) – Each item in this sequence will be passed to ff (
Callable
[[~T],DataFrame
]) – Function that generates a pandas dataframe that will be called on argumentsfile_name (
Union
[str
,Path
]) – Name of the file to writewrite_index (
bool
) – Write the pandas index to the csv filecolumns (
Optional
[Sequence
[str
]]) – which columns to write. If this is set the index is not writtenwrite_mode (
Literal
[‘w’, ‘a’]) – set the initial write mode. “a” to append, “w” to overwrite. Useful for resuming downloading.
Usage:
>>> %pip install calcbench-api-client[Pandas,Backoff,tqdm] >>> from calcbench.downloaders import iterate_and_save_pandas >>> import calcbench as cb >>> tickers = cb.tickers(entire_universe=True) >>> iterate_and_save_pandas( >>> arguments=tickers, >>> f=lambda ticker: cb.standardized(company_identifiers=[ticker], point_in_time=True), >>> file_name="calcbench_standardized_PIT.csv", >>> )
- calcbench.downloaders.iterate_to_dataframe(arguments, f)¶
Apply arguments to a function that returns a DataFrame append to a dataframe and return.
Usage:
>>> %pip install calcbench-api-client[Pandas,Backoff,tqdm] >>> from calcbench.downloaders import iterate_to_dataframe >>> import calcbench as cb >>> tickers = cb.tickers(entire_universe=True) >>> d = iterate_and_save_pandas( >>> tickers, >>> lambda ticker: cb.point_in_time( >>> all_face=True, >>> all_footnotes=False, >>> company_identifiers=[ticker], >>> all_history=True, >>> include_preliminary=True, >>> include_xbrl=True, >>> ), >>> )
- Return type
DataFrame