--------------------------------------------------------------------------- OSError…
- User
OSError Traceback (most recent call last) Cell In[15], line 7 4 grqs_latam = grqs_latam.drop(['Policy Violation', 'Country', 'Region'], axis=1) 5 grqs_na = grqs[grqs.Region == 'NA'] ----> 7 grqs_emea.to_excel('Cleaned_NonAPAC/grqs_emea.xlsx', index = False) 8 grqs_latam.to_excel('Cleaned_NonAPAC/grqs_latam.xlsx', index = False) 9 grqs_na.to_excel('Cleaned_NonAPAC/grqs_na.xlsx', index = False)
File ~/anaconda3/lib/python3.10/site-packages/pandas/util/_decorators.py:211, in deprecate_kwarg.._deprecate_kwarg..wrapper(*args, **kwargs) 209 else: 210 kwargs[new_arg_name] = new_arg_value --> 211 return func(*args, **kwargs)
File ~/anaconda3/lib/python3.10/site-packages/pandas/util/_decorators.py:211, in deprecate_kwarg.._deprecate_kwarg..wrapper(*args, **kwargs) 209 else: 210 kwargs[new_arg_name] = new_arg_value --> 211 return func(*args, **kwargs)
File ~/anaconda3/lib/python3.10/site-packages/pandas/core/generic.py:2374, in NDFrame.to_excel(self, excel_writer, sheet_name, na_rep, float_format, columns, header, index, index_label, startrow, startcol, engine, merge_cells, encoding, inf_rep, verbose, freeze_panes, storage_options) 2361 from pandas.io.formats.excel import ExcelFormatter 2363 formatter = ExcelFormatter( 2364 df, 2365 na_rep=na_rep, (...) 2372 inf_rep=inf_rep, 2373 ) -> 2374 formatter.write( 2375 excel_writer, 2376 sheet_name=sheet_name, 2377 startrow=startrow, 2378 startcol=startcol, 2379 freeze_panes=freeze_panes, 2380 engine=engine, 2381 storage_options=storage_options, 2382 )
File ~/anaconda3/lib/python3.10/site-packages/pandas/io/formats/excel.py:944, in ExcelFormatter.write(self, writer, sheet_name, startrow, startcol, freeze_panes, engine, storage_options) 940 need_save = False 941 else: 942 # error: Cannot instantiate abstract class 'ExcelWriter' with abstract 943 # attributes 'engine', 'save', 'supported_extensions' and 'write_cells' --> 944 writer = ExcelWriter( # type: ignore[abstract] 945 writer, engine=engine, storage_options=storage_options 946 ) 947 need_save = True 949 try:
File ~/anaconda3/lib/python3.10/site-packages/pandas/io/excel/_openpyxl.py:60, in OpenpyxlWriter.init(self, path, engine, date_format, datetime_format, mode, storage_options, if_sheet_exists, engine_kwargs, **kwargs) 56 from openpyxl.workbook import Workbook 58 engine_kwargs = combine_kwargs(engine_kwargs, kwargs) ---> 60 super().init( 61 path, 62 mode=mode, 63 storage_options=storage_options, 64 if_sheet_exists=if_sheet_exists, 65 engine_kwargs=engine_kwargs, 66 ) 68 # ExcelWriter replaced "a" by "r+" to allow us to first read the excel file from 69 # the file and later write to it 70 if "r+" in self._mode: # Load from existing workbook
File ~/anaconda3/lib/python3.10/site-packages/pandas/io/excel/_base.py:1313, in ExcelWriter.init(self, path, engine, date_format, datetime_format, mode, storage_options, if_sheet_exists, engine_kwargs, **kwargs) 1309 self._handles = IOHandles( 1310 cast(IO[bytes], path), compression={"compression": None} 1311 ) 1312 if not isinstance(path, ExcelWriter): -> 1313 self._handles = get_handle( 1314 path, mode, storage_options=storage_options, is_text=False 1315 ) 1316 self._cur_sheet = None 1318 if date_format is None:
- Assistant
The error message indicates that the directory 'Cleaned_NonAPAC' does not exist. You need to create this directory before saving the Excel files into it. You can use the following code to create the directory:
pythonimport os directory = 'Cleaned_NonAPAC' if not os.path.exists(directory): os.makedirs(directory)Place this code before the line where you save the Excel files:
pythongrqs_emea.to_excel('Cleaned_NonAPAC/grqs_emea.xlsx', index=False) grqs_latam.to_excel('Cleaned_NonAPAC/grqs_latam.xlsx', index=False) grqs_na.to_excel('Cleaned_NonAPAC/grqs_na.xlsx', index=False)