feat: T1 guardar e T4 feitos

This commit is contained in:
2025-11-03 23:31:30 -01:00
parent 66dff395fd
commit 7780ee2e4e
2 changed files with 24 additions and 8 deletions

View File

@@ -1,8 +1,29 @@
#! /usr/bin/env python
import pandas as pd
import json
from parser import parse
def guardar_df(df: pd.DataFrame, fname: str) -> bool:
with open(fname, "w") as fp:
fname = f"{fname}.txt"
try:
fp.write(df.to_string())
except ValueError:
return False
return True
def guardar_json(df: pd.DataFrame, fname: str) -> bool:
with open(fname , "w") as fp:
try:
json.dump(df.to_json(), fp)
except:
return False
return True
def main():
pass

View File

@@ -32,12 +32,6 @@ def into_dataframe(data) -> pd.DataFrame:
return pd.DataFrame(data=aux)
def test(d1, d2):
for col in d2.columns:
d1.at[0, col] = d2[col].tolist()
return d1
# ------------ principal
def parse(fname="dados.txt"):
@@ -49,7 +43,9 @@ def parse(fname="dados.txt"):
a = parse_chunk(data[c[0]:c[1]], idx)
aux = pd.concat([df, a], axis=0, ignore_index=True)
df = aux
print(df)
aux = df.loc[df["ID"] == 14]
print(aux)
fp.close()
return df
@@ -80,7 +76,6 @@ def parse_chunk(chunk_lines: list[str], iD):
hDF = into_dataframe(headersRet)
hDF["ID"] = iD
phaseRet["ID"] = iD
return pd.concat([hDF, phaseRet])