Created
December 24, 2022 21:04
-
-
Save noemk2/6fd0355ca1588de6bb1b265a8c82c4a0 to your computer and use it in GitHub Desktop.
pandas group by query group by search if repeat id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import datetime as dt | |
| ventas = pd.read_csv("../tablas_cp/venta.csv") | |
| # print(ventas) | |
| ventas["Fecha"] = pd.to_datetime(ventas["Fecha"]) | |
| # print(venta[venta.Cantidad == 1]) | |
| # quiero saber el total de clientes que compraron en el 2019 | |
| query_2019_ventas = ventas[ventas["Fecha"].dt.year == 2019] | |
| # print(ventas.iloc[3]) | |
| two_colum = query_2019_ventas[["IdCliente", "IdSucursal"]] | |
| # grupo = two_colum.groupby("IdCliente") | |
| grupo = two_colum.groupby("IdCliente") | |
| contenedor = 0 | |
| for name, group in grupo: | |
| # group["IdSucursal"].drop_duplicates(keep=False) | |
| if group["IdSucursal"].drop_duplicates(keep=False).empty: | |
| # print(name) | |
| contenedor += 1 | |
| print() | |
| print(contenedor) | |
| # print(grupo.get_group(1)) | |
| # for x in range(1675): | |
| # print(grupo.get_group(x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment