Spaces:
Sleeping
Sleeping
AnnasBlackHat
commited on
Commit
•
67ef6b6
1
Parent(s):
71c9c71
fix sock price order
Browse files
app.py
CHANGED
@@ -80,13 +80,13 @@ def format_df(data):
|
|
80 |
if data == '' : return tables
|
81 |
|
82 |
df = pd.json_normalize(data)
|
83 |
-
# Check if column exists
|
84 |
for col in ["price", "created_at"]:
|
85 |
if col not in df.columns:
|
86 |
# If not, add the column and fill with NaN or other default
|
87 |
df[col] = 0
|
88 |
|
89 |
-
# Check if column exists
|
90 |
for col in ["stock_out_source", "stock_out_id"]:
|
91 |
if col not in df.columns:
|
92 |
# If not, add the column and fill with NaN or other default
|
@@ -109,9 +109,11 @@ def format_df(data):
|
|
109 |
grouped_data = df.groupby("stock_price_id").agg(
|
110 |
{"product_name": "first", "outlet_name": "first", "price": "first",
|
111 |
"stock_in": "first", "stock_out_total": "first", "stock_in_source": "first",
|
112 |
-
"stock_in_id": "first", "stock in": "first", "date_in":"first"}
|
113 |
).reset_index()
|
114 |
|
|
|
|
|
115 |
# Iterate through groups and display main and detail tables
|
116 |
for index, row in grouped_data.iterrows():
|
117 |
main_table = pd.DataFrame([row], columns=["stock in", "price", "stock_in"])
|
|
|
80 |
if data == '' : return tables
|
81 |
|
82 |
df = pd.json_normalize(data)
|
83 |
+
# Check if column exists (number)
|
84 |
for col in ["price", "created_at"]:
|
85 |
if col not in df.columns:
|
86 |
# If not, add the column and fill with NaN or other default
|
87 |
df[col] = 0
|
88 |
|
89 |
+
# Check if column exists (sting)
|
90 |
for col in ["stock_out_source", "stock_out_id"]:
|
91 |
if col not in df.columns:
|
92 |
# If not, add the column and fill with NaN or other default
|
|
|
109 |
grouped_data = df.groupby("stock_price_id").agg(
|
110 |
{"product_name": "first", "outlet_name": "first", "price": "first",
|
111 |
"stock_in": "first", "stock_out_total": "first", "stock_in_source": "first",
|
112 |
+
"stock_in_id": "first", "stock in": "first", "date_in":"first", "created_at_in": "first"}
|
113 |
).reset_index()
|
114 |
|
115 |
+
grouped_data = grouped_data.sort_values(by="created_at_in")
|
116 |
+
|
117 |
# Iterate through groups and display main and detail tables
|
118 |
for index, row in grouped_data.iterrows():
|
119 |
main_table = pd.DataFrame([row], columns=["stock in", "price", "stock_in"])
|