Skip to content

Commit 8f8c3ca

Browse files
RenaissanceAIExtractTable
authored andcommitted
Removed orient and transposed the dataframes (#7)
Thanks a ton. Please accept extra credits added to your account as our gratitude.
1 parent b43d1e4 commit 8f8c3ca

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

ExtractTable/common.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ def __init__(self, data: dict, fmt: str = DEFAULT, index: bool=False):
2424
self.data = data
2525
self.output = self._converter(fmt.lower(), index=index)
2626

27-
def _converter(self, fmt: str, orient: str = "index", index: bool = False) -> list:
27+
def _converter(self, fmt: str, index: bool = False) -> list:
2828
"""
2929
Actual conversion takes place here using Pandas
3030
:param fmt: format to be converted into
3131
:param orient: required orientation of tabualar data in the output
3232
:param index: row index consideration in the output
3333
:return: list of tables from converted into the requested output format
3434
"""
35-
dfs = [pd.read_json(json.dumps(table["TableJson"]), orient=orient) for table in self.data["Tables"]]
35+
dfs = [pd.read_json(json.dumps(table["TableJson"]).T) for table in self.data["Tables"]]
3636
if fmt in ("df", "dataframe"):
3737
return dfs
3838
if fmt == "dict":
39-
return [df.to_dict(orient=orient) for df in dfs]
39+
return [df.to_dict() for df in dfs]
4040
elif fmt == "csv":
4141
save_folder = tempfile.mkdtemp()
4242
output_location = []
@@ -46,7 +46,7 @@ def _converter(self, fmt: str, orient: str = "index", index: bool = False) -> li
4646
output_location.append(csv_name)
4747
return output_location
4848
elif fmt == "json":
49-
return [df.to_json(orient=orient) for df in dfs]
49+
return [df.to_json() for df in dfs]
5050
else:
5151
warn_msg = f"Supported output formats {self.FORMATS} only. Assigned to default: {self.DEFAULT}"
5252
warnings.warn(warn_msg)

0 commit comments

Comments
 (0)