| 49 | return df |
| 50 | |
| 51 | def write_csv(file_path: str, data_dict: dict): |
| 52 | # transform data of one row to DataFrame |
| 53 | new_row = pd.DataFrame([data_dict]) |
| 54 | |
| 55 | # directly save when the file does not exist; else we just append |
| 56 | if not osp.isfile(file_path): |
| 57 | new_row.to_csv(file_path, index=False) |
| 58 | else: |
| 59 | existing_data = pd.read_csv(file_path) |
| 60 | updated_data = pd.concat([existing_data, new_row], ignore_index=True) |
| 61 | updated_data.to_csv(file_path, index=False) |
| 62 | |
| 63 | def format_matrix_str(matrix): |
| 64 | def format_float(num, total_width=20, decimal_places=12): |