Python Forum
Filter data into new dataframe as main dataframe is being populated
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Filter data into new dataframe as main dataframe is being populated
#9
Here is my test script updated and working as expected. Just need to replace the "statusResults" dataframe with the dynamically generated one in the main script, but i feel good about this working in production.

# THIS IS TEMPORARY UNTIL MOVED TO REAL SCRIPT(THIS WILL BE THE PING RESULTS BEFORE WRITING TO CSV)
statusResults = pd.read_csv("Register_ip_output_20231021_233512.csv",names=['IP', 'Store', 'Register','Status', 'Datetime'])

# Compute what % of registers are offline
by_store = statusResults.groupby("Store")
status = by_store["Status"]
report = pd.concat([status.size(), status.sum()], axis=1).reset_index()
report.columns = ["Store", "Register Count", "Percentage"]
report["Percentage"] = report["Percentage"] / report["Register Count"] * 100
statuscntUp = len(statusResults[statusResults["Status"] == False])

# USED TO CALCULATE NUMBER OF STORES WITH A % OF REGISTERS DOWN
percentDown = len(report[report["Percentage"] != 0].index)
# RETURNS THE TOTAL NUMBER OF REGISTERS CHECKED
RegisterCount = report["Register Count"].sum()
# TOTAL CHAIN % OF REGISTERS UP
TotalPercentUp = str(int(statuscntUp / RegisterCount * 100)) + "%"

# LIST OF STORES FOR DISPLAYING ON SCREEN(FORMATTED)
TwentyStores = ','.join(str(v) for v in report[(report["Percentage"] > 20) & (report["Percentage"] < 50)]["Store"].values)
# GETS COUNT OF STORES WITH MORE THAN 20%
TwentyPercent = len(report[(report["Percentage"] > 20) & (report["Percentage"] < 50)]["Store"].values)

# GETS COUNT OF STORES WITH MORE THAN 50%
FiftyPercent = len(report[report["Percentage"] >= 50]["Store"].values)
# LIST OF STORES FOR DISPLAYING ON SCREEN(FORMATTED)
FiftyStores = ','.join(str(v) for v in report[report["Percentage"] >= 50]["Store"].values)
Reply


Messages In This Thread
RE: Filter data into new dataframe as main dataframe is being populated - by cubangt - Oct-23-2023, 12:43 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries sawtooth500 14 669 Apr-24-2024, 01:42 AM
Last Post: sawtooth500
  Elegant way to apply each element of an array to a dataframe? sawtooth500 7 479 Mar-29-2024, 05:51 PM
Last Post: deanhystad
  Dataframe copy warning sawtooth500 4 403 Mar-25-2024, 11:38 PM
Last Post: sawtooth500
  FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries i sawtooth500 3 1,554 Mar-22-2024, 03:08 AM
Last Post: deanhystad
  Adding PD DataFrame column bsben 2 354 Mar-08-2024, 10:46 PM
Last Post: deanhystad
  Python Alteryx QS-Passing pandas dataframe column inside SQL query where condition sanky1990 0 772 Dec-04-2023, 09:48 PM
Last Post: sanky1990
  Comparing Dataframe to String? RockBlok 2 441 Nov-24-2023, 04:55 PM
Last Post: RockBlok
  DataFRame.concat() nafshar 3 818 Jul-14-2023, 04:41 PM
Last Post: nafshar
  Convert dataframe from str back to datafarme Creepy 1 659 Jul-07-2023, 02:13 PM
Last Post: snippsat
  Question on pandas.dataframe merging two colums shomikc 4 884 Jun-29-2023, 11:30 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020