Skip to content

Commit

Permalink
feat: define which columns to convert to numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
martinkersner committed Jul 20, 2024
1 parent cb3edb3 commit f30ed88
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion datamaxi/datamaxi/dex_trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def next_request():
)

if pandas:
df = convert_data_to_data_frame(res["data"])
df = convert_data_to_data_frame(res["data"], ["b", "bq", "qq", "p", "usd"])
return df, next_request
else:
return res, next_request
Expand Down
18 changes: 15 additions & 3 deletions datamaxi/datamaxi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@
import pandas as pd


def convert_data_to_data_frame(data: List) -> pd.DataFrame:
def convert_data_to_data_frame(
data: List,
columns_to_replace: List[str] = [],
) -> pd.DataFrame:
df = pd.DataFrame(data)
df = df.set_index("d")
df.replace("NaN", pd.NA, inplace=True)
df = df.apply(pd.to_numeric, errors="coerce")

if len(columns_to_replace) == 0:
df.replace("NaN", pd.NA, inplace=True)
df = df.apply(pd.to_numeric, errors="coerce")
return df

df[columns_to_replace] = df[columns_to_replace].replace("NaN", pd.NA)
df[columns_to_replace] = df[columns_to_replace].apply(
pd.to_numeric, errors="coerce"
)

return df

0 comments on commit f30ed88

Please sign in to comment.