def list2array(self): """ Set internal storage for timeseries data. Open file and read data into internal storage. """ Model.list2array(self) # read and store data for ii in range(self.n): idx = self.idx.v[ii] path = self.path.v[ii] sheet = self.sheet.v[ii] try: df = pd.read_excel(path, sheet_name=sheet) except FileNotFoundError as e: logger.error('<%s idx=%s>: File not found: "%s"', self.class_name, idx, path) raise e except ValueError as e: logger.error('<%s idx=%s>: Sheet not found: "%s" in "%s"', self.class_name, idx, sheet, path) raise e for field in self.fields.v[ii]: if field not in df.columns: raise ValueError('Field {} not found in timeseries data'.format(field)) self._data[idx] = df
def read(system, infile): """ Read an xlsx file with ANDES model data into an empty system Parameters ---------- system : System Empty System instance infile : str or file-like Path to the input file, or a file-like object Returns ------- System System instance after succeeded """ df_models = pd.read_excel(infile, sheet_name=None, index_col=0, engine='openpyxl', ) for name, df in df_models.items(): # drop rows that all nan df.dropna(axis=0, how='all', inplace=True) for row in df.to_dict(orient='records'): system.add(name, row) # --- for debugging --- system.df_in = df_models return system
def read(system, infile): """ Read an xlsx file with ANDES model data into an empty system Parameters ---------- system : System Empty System instance infile : str Path to the input file Returns ------- System System instance after succeeded """ with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=PendingDeprecationWarning) warnings.filterwarnings("ignore", category=DeprecationWarning) df_models = pd.read_excel(infile, sheet_name=None, index_col=0) for name, df in df_models.items(): for row in df.to_dict(orient='records'): system.add(name, row) return system
def _read_excel(self, path, sheet, idx): """ Helper function to read excel file. """ try: df = pd.read_excel(path, sheet_name=sheet) return df except ValueError as e: logger.error('<%s idx=%s>: Sheet not found: "%s" in "%s"', self.class_name, idx, sheet, path) raise e
def excel_to_df(file, offset_row=6, offset_col=0): """ Convert a XLS export to DataFrame TSAT offset is 6, PSS/E offset is 1 """ wb = pd.read_excel(file) df = wb.iloc[offset_row:, offset_col:] df.transpose() df.columns = ['Time', *range(len(df.columns) - 1)] return df