diff --git a/evdspy/EVDSlocal/components/evds_files.py b/evdspy/EVDSlocal/components/evds_files.py index 269b723..9aa8fdf 100644 --- a/evdspy/EVDSlocal/components/evds_files.py +++ b/evdspy/EVDSlocal/components/evds_files.py @@ -185,7 +185,8 @@ def check_cols(x: str): for other_column in other_cols: self.df[other_column] = old_df[other_column] except: - print_with_failure_style("Could not convert some columns to float type...") + # print_with_failure_style("Could not convert some columns to float type...") + ... def convert_csv_df(self, csv_buffer: str): if not csv_buffer: return False diff --git a/evdspy/EVDSlocal/index_requests/df_operations.py b/evdspy/EVDSlocal/index_requests/df_operations.py index f3dc7b5..16e99f8 100644 --- a/evdspy/EVDSlocal/index_requests/df_operations.py +++ b/evdspy/EVDSlocal/index_requests/df_operations.py @@ -59,7 +59,8 @@ def check_cols(x: str): try: self.df = self.df[columns].astype(float) except: - print_with_failure_style("Could not convert some columns to float type...") + # print_with_failure_style("Could not convert some columns to float type...") + ... for other_column in other_cols: self.df[other_column] = old_df[other_column] def convert_to_df_abstract(self): diff --git a/evdspy/EVDSlocal/index_requests/index_util_funcs.py b/evdspy/EVDSlocal/index_requests/index_util_funcs.py index 85fc966..7bfe8a0 100644 --- a/evdspy/EVDSlocal/index_requests/index_util_funcs.py +++ b/evdspy/EVDSlocal/index_requests/index_util_funcs.py @@ -1,24 +1,31 @@ - import pandas as pd import typing as t from ..common.colors import print_with_failure_style from ..components.excel_class import correct_folder + + def make_date_first_column_helper(df, col_name): if col_name not in df.columns: return df cols = [col_name] + [col for col in df if col != col_name] df = df[cols] return df + + def make_date_first_column(df): col_names = ('YEARWEEK', 'Tarih',) for col_name in col_names: df = make_date_first_column_helper(df, col_name) return df + + def drop_unix(df): UnixTime = 'UNIXTIME' if UnixTime in df.columns: df.drop(UnixTime, axis=1, inplace=True) return df + + def json_to_df(json_content: t.Union[list, dict]): if hasattr(json_content, 'items'): json_content = json_content['items'] @@ -26,6 +33,8 @@ def json_to_df(json_content: t.Union[list, dict]): df = drop_unix(df) df = make_date_first_column(df) return df + + def make_df_float(df): def check_cols(x: str): items = ( @@ -35,16 +44,20 @@ def check_cols(x: str): "YEAR" not in x, ) return all(items) + columns = (x for x in df.columns if check_cols(x)) other_cols = (x for x in df.columns if not check_cols(x)) old_df = df try: df = df[columns].astype(float) except: - print_with_failure_style("Could not convert some columns to float type...") + # print_with_failure_style("Could not convert some columns to float type...") + ... for other_column in other_cols: df[other_column] = old_df[other_column] return df + + def json_to_excel(json_content: list, file_name, try_float=True): file_name = correct_folder(file_name, "xlsx") df = json_to_df(json_content) @@ -54,4 +67,4 @@ def json_to_excel(json_content: list, file_name, try_float=True): df = make_date_first_column(df) df.to_excel(file_name) except: - print(f"could not write excel file {file_name}. =>file is probably open") \ No newline at end of file + print(f"could not write excel file {file_name}. =>file is probably open")