save_local
Save an object to a local file based on its extension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Path where to save the file |
required |
|
Optional[object]
|
The object to save. Type requirements depend on the file extension: - .csv, .parquet: pandas DataFrame - .xlsx, .xls: pandas DataFrame or dict of DataFrames - .json: Any JSON-serializable object or pandas DataFrame - .pkl: Any picklable object - .png: Active matplotlib figure - .geojson: GeoDataFrame |
None
|
|
Additional arguments for saving: - CSV: index, encoding, etc. - Excel: sheet_name, index, etc. - JSON: indent, orient, etc. - Others: format-specific options |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the file extension is not supported |
TypeError
|
If obj type doesn't match the file extension requirements |
IOError
|
If there are issues writing to the file |
OSError
|
If the directory structure doesn't exist |
Examples:
Save DataFrame to CSV:
Save multiple DataFrames to Excel sheets:
>>> sheets = {
... 'Sales': sales_df,
... 'Costs': costs_df
... }
>>> save_local('report.xlsx', sheets)
Save matplotlib figure:
Notes
- Parent directories will be created if they don't exist
- For Excel files with multiple sheets, sheet names are truncated to 31 chars
Source code in dashboard_template_database/storage/local/saver.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |