import pandas as pd
df_norte = pd.read_csv("./ventas_norte.csv", sep=";", dtype={"Cantidad_Vendida": int, "Precio_Unit": int, "Nom_Producto": str}, parse_dates=["Fecha_Venta"], index_col="ID_Transaccion")
df_norte["region"] = "Norte"
df_norte
| Fecha_Venta | Nom_Producto | Cantidad_Vendida | Precio_Unit | region | |
|---|---|---|---|---|---|
| ID_Transaccion | |||||
| 1000 | 2023-02-21 | Laptop | 4 | 423 | Norte |
| 1001 | 2023-01-15 | Laptop | 2 | 171 | Norte |
| 1002 | 2023-03-13 | Laptop | 3 | 73 | Norte |
| 1003 | 2023-03-02 | Teclado | 1 | 139 | Norte |
| 1004 | 2023-01-21 | Monitor | 4 | 692 | Norte |
| ... | ... | ... | ... | ... | ... |
| 1095 | 2023-02-10 | Laptop | 3 | 516 | Norte |
| 1096 | 2023-01-29 | Monitor | 3 | 321 | Norte |
| 1097 | 2023-01-15 | Laptop | 4 | 200 | Norte |
| 1098 | 2023-02-14 | Mouse | 4 | 626 | Norte |
| 1099 | 2023-03-06 | Mouse | 3 | 118 | Norte |
100 rows × 5 columns
df_norte.info()
<class 'pandas.core.frame.DataFrame'>
Index: 100 entries, 1000 to 1099
Data columns (total 5 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Fecha_Venta 100 non-null datetime64[ns]
1 Nom_Producto 100 non-null object
2 Cantidad_Vendida 100 non-null int64
3 Precio_Unit 100 non-null int64
4 region 100 non-null object
dtypes: datetime64[ns](1), int64(2), object(2)
memory usage: 4.7+ KB
df_sur = pd.read_excel("./ventas_sur.xlsx", names=["ID_Transaccion", "Fecha_Venta", "Nom_Producto", "Cantidad_Vendida", "Precio_Unit"], dtype={"Cantidad_Vendida": int, "Precio_Unit": int, "Nom_Producto": str}, parse_dates=["Fecha_Venta"], index_col="ID_Transaccion")
df_sur["region"] = "Sur"
df_sur
| Fecha_Venta | Nom_Producto | Cantidad_Vendida | Precio_Unit | region | |
|---|---|---|---|---|---|
| ID_Transaccion | |||||
| 2000 | 2023-03-01 | Monitor | 6 | 624 | Sur |
| 2001 | 2023-03-04 | Laptop | 7 | 941 | Sur |
| 2002 | 2023-03-26 | Mouse | 3 | 989 | Sur |
| 2003 | 2023-02-01 | Webcam | 3 | 621 | Sur |
| 2004 | 2023-03-28 | Mouse | 5 | 437 | Sur |
| 2005 | 2023-02-02 | Mouse | 6 | 134 | Sur |
| 2006 | 2023-03-08 | Laptop | 9 | 636 | Sur |
| 2007 | 2023-01-18 | Teclado | 5 | 922 | Sur |
| 2008 | 2023-01-25 | Mouse | 1 | 215 | Sur |
| 2009 | 2023-02-23 | Monitor | 4 | 845 | Sur |
| 2010 | 2023-02-27 | Teclado | 5 | 520 | Sur |
| 2011 | 2023-03-08 | Webcam | 5 | 645 | Sur |
| 2012 | 2023-02-15 | Laptop | 7 | 512 | Sur |
| 2013 | 2023-01-24 | Webcam | 4 | 94 | Sur |
| 2014 | 2023-02-01 | Teclado | 1 | 432 | Sur |
| 2015 | 2023-02-16 | Teclado | 5 | 395 | Sur |
| 2016 | 2023-03-27 | Teclado | 7 | 439 | Sur |
| 2017 | 2023-01-23 | Webcam | 6 | 748 | Sur |
| 2018 | 2023-03-07 | Teclado | 5 | 296 | Sur |
| 2019 | 2023-01-27 | Webcam | 4 | 780 | Sur |
| 2020 | 2023-01-02 | Teclado | 2 | 695 | Sur |
| 2021 | 2023-03-31 | Monitor | 4 | 413 | Sur |
| 2022 | 2023-01-17 | Teclado | 3 | 888 | Sur |
| 2023 | 2023-02-02 | Webcam | 1 | 476 | Sur |
| 2024 | 2023-01-09 | Mouse | 8 | 939 | Sur |
| 2025 | 2023-02-12 | Teclado | 5 | 211 | Sur |
| 2026 | 2023-02-17 | Mouse | 4 | 758 | Sur |
| 2027 | 2023-02-08 | Monitor | 8 | 708 | Sur |
| 2028 | 2023-02-11 | Laptop | 7 | 118 | Sur |
| 2029 | 2023-01-26 | Monitor | 2 | 567 | Sur |
| 2030 | 2023-02-19 | Teclado | 1 | 997 | Sur |
| 2031 | 2023-01-25 | Mouse | 4 | 115 | Sur |
| 2032 | 2023-01-24 | Mouse | 8 | 683 | Sur |
| 2033 | 2023-01-13 | Webcam | 2 | 682 | Sur |
| 2034 | 2023-03-01 | Mouse | 3 | 209 | Sur |
| 2035 | 2023-01-07 | Webcam | 1 | 755 | Sur |
| 2036 | 2023-02-26 | Laptop | 1 | 56 | Sur |
| 2037 | 2023-02-05 | Teclado | 3 | 799 | Sur |
| 2038 | 2023-02-14 | Webcam | 5 | 388 | Sur |
| 2039 | 2023-01-20 | Laptop | 3 | 714 | Sur |
| 2040 | 2023-03-06 | Mouse | 1 | 544 | Sur |
| 2041 | 2023-01-08 | Mouse | 1 | 298 | Sur |
| 2042 | 2023-01-16 | Laptop | 8 | 236 | Sur |
| 2043 | 2023-01-14 | Mouse | 2 | 886 | Sur |
| 2044 | 2023-03-17 | Laptop | 3 | 892 | Sur |
| 2045 | 2023-03-28 | Webcam | 2 | 817 | Sur |
| 2046 | 2023-01-15 | Webcam | 3 | 292 | Sur |
| 2047 | 2023-03-07 | Laptop | 7 | 900 | Sur |
| 2048 | 2023-02-01 | Webcam | 1 | 81 | Sur |
| 2049 | 2023-03-28 | Webcam | 8 | 615 | Sur |
import json
with open("./ventas_este.json") as f:
info = json.load(f)
df_este = pd.json_normalize(info)
df_este = df_este[["id_orden", "timestamp", "detalles_producto.nombre", "detalles_producto.specs.cantidad", "detalles_producto.specs.precio"]]
df_este["timestamp"] = df_este["timestamp"].apply(lambda x: x.split(" ")[0])
df_este = df_este.rename(columns={"id_orden": "ID_Transaccion", "timestamp": "Fecha_Venta", "detalles_producto.nombre": "Nom_Producto", "detalles_producto.specs.cantidad": "Cantidad_Vendida", "detalles_producto.specs.precio": "Precio_Unit"})
df_este = df_este.set_index("ID_Transaccion")
df_este["region"] = "Este"
df_este
| Fecha_Venta | Nom_Producto | Cantidad_Vendida | Precio_Unit | region | |
|---|---|---|---|---|---|
| ID_Transaccion | |||||
| ORD-3000 | 2023-03-09 | Monitor | 2 | 244 | Este |
| ORD-3001 | 2023-01-20 | Laptop | 2 | 578 | Este |
| ORD-3002 | 2023-01-01 | Mouse | 2 | 339 | Este |
| ORD-3003 | 2023-02-07 | Webcam | 2 | 158 | Este |
| ORD-3004 | 2023-03-18 | Monitor | 1 | 692 | Este |
| ... | ... | ... | ... | ... | ... |
| ORD-3095 | 2023-03-28 | Webcam | 1 | 857 | Este |
| ORD-3096 | 2023-01-18 | Webcam | 2 | 375 | Este |
| ORD-3097 | 2023-02-10 | Mouse | 1 | 696 | Este |
| ORD-3098 | 2023-01-25 | Mouse | 2 | 618 | Este |
| ORD-3099 | 2023-03-27 | Webcam | 1 | 844 | Este |
100 rows × 5 columns
df_junto = pd.concat([df_norte, df_sur, df_este])
df_junto
| Fecha_Venta | Nom_Producto | Cantidad_Vendida | Precio_Unit | region | |
|---|---|---|---|---|---|
| ID_Transaccion | |||||
| 1000 | 2023-02-21 00:00:00 | Laptop | 4 | 423 | Norte |
| 1001 | 2023-01-15 00:00:00 | Laptop | 2 | 171 | Norte |
| 1002 | 2023-03-13 00:00:00 | Laptop | 3 | 73 | Norte |
| 1003 | 2023-03-02 00:00:00 | Teclado | 1 | 139 | Norte |
| 1004 | 2023-01-21 00:00:00 | Monitor | 4 | 692 | Norte |
| ... | ... | ... | ... | ... | ... |
| ORD-3095 | 2023-03-28 | Webcam | 1 | 857 | Este |
| ORD-3096 | 2023-01-18 | Webcam | 2 | 375 | Este |
| ORD-3097 | 2023-02-10 | Mouse | 1 | 696 | Este |
| ORD-3098 | 2023-01-25 | Mouse | 2 | 618 | Este |
| ORD-3099 | 2023-03-27 | Webcam | 1 | 844 | Este |
250 rows × 5 columns
df_junto.to_csv(index=False, sep=",", encoding="utf-8", path_or_buf="./ventas_consolidadas.csv")