Skip to content

Commit

Permalink
verbose float
Browse files Browse the repository at this point in the history
  • Loading branch information
SermetPekin committed Aug 3, 2024
1 parent 96a1a7b commit 86bbcbd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
3 changes: 2 additions & 1 deletion evdspy/EVDSlocal/components/evds_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion evdspy/EVDSlocal/index_requests/df_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
19 changes: 16 additions & 3 deletions evdspy/EVDSlocal/index_requests/index_util_funcs.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@

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']
df = pd.DataFrame.from_records(json_content)
df = drop_unix(df)
df = make_date_first_column(df)
return df


def make_df_float(df):
def check_cols(x: str):
items = (
Expand All @@ -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)
Expand All @@ -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")
print(f"could not write excel file {file_name}. =>file is probably open")

0 comments on commit 86bbcbd

Please sign in to comment.