import pandas as pd sampleData = [ { "id": 0, "Hospital": "SomeHospital", "VetcoveItemID": 123, "Name": "IDEXX VETCONNECT PLUS", "Frequency": "Weekly", "hide": True }, { "id": 1, "Hospital": "SomeHospital", "VetcoveItemID": 124, "Name": "IDEXX VETLAB WIRELESS ROUTER & SWITCH", "Frequency": "EOW", "hide": False }, { "id": 2, "Hospital": "SomeHospital", "VetcoveItemID": 125, "Name": "Lymph Node Aspirate Transport Tube: 2mL 5 Count", "Frequency": "Monthly", "hide": False }, { "id": 3, "Hospital": "SomeHospital", "VetcoveItemID": 126, "Name": "PROCYTEDX ANALYZER SYSTEM WITHOUT IVLS", "Frequency": "Quarterly", "hide": False }, { "id": 4, "Hospital": "SomeHospital", "VetcoveItemID": 127, "Name": "SAFETY PRECAUTIONS FOR CATALYST ONE", "Frequency": "Weekly", "hide": False } ] df = pd.DataFrame(sampleData) weekNumbers = {} for i in range(0,52): weekstring = "week"+str(i) weekNumbers[weekstring]="week" idAndWeeks = pd.DataFrame([weekNumbers]) print(idAndWeeks) def make_weeks(): #this doesnt do anything fun, but it got me to the solution weeksAndFrequency = list(weekNumbers.keys()) weeksAndFrequency.append("Frequency") print(weeksAndFrequency) df1 = pd.concat([idAndWeeks,df],axis="columns") print("df1 head ",df1.head(20)) print("df1 weekly just weeks: ",df1.loc[df1.Frequency=="Weekly",weekNumbers.keys()].head()) df1.loc[df1.Frequency=="Weekly",weekNumbers.keys()] = True print("df1 weekly just weeks AFTER CHANGE: ",df1.loc[df1.Frequency=="Weekly",weekNumbers.keys()].head()) print("df1 index isin: ",df1.index.isin(df1.index[:2])) print("df1 EOW index frequency: ",df1.loc[(df1.Frequency=="EOW") & (df1.index.isin(df1.index[::2])),list(weekNumbers.keys())[::2]].head()) frequencyRowSelector = df1.Frequency=="EOW" everyNthRowSelector = df1.index.isin(df1.index[::2]) columnsToSetSelector = list(weekNumbers.keys())[::2] #df1.loc[(df1.Frequency=="EOW") & (df1.index.isin(df1.index[::2])),list(weekNumbers.keys())[::2]]=True df1.loc[frequencyRowSelector & everyNthRowSelector,columnsToSetSelector]=True print("df1 EOW just weeks AFTER CHANGE: \n",df1.loc[df1.Frequency=="EOW",weeksAndFrequency].head()) print("test") # each item should have "active" weeks based on frequency and even distribution of items per week # process each item, in batches of frequency (ie: EOW all together) and just assign numbers in order. # EOW is week on/week off with 50% of items on week 1 and 50% on week 2, for example # item appears on main table if week is true (there are 52 weeks and 12 (or 13? cause thats easier in python than excel) # weeks of cycle so math is hard) def make_week_data(): #this WORKS!?!?! weeksAndFrequency = list(weekNumbers.keys()) weeksAndFrequency.append("Frequency") print(weeksAndFrequency) df1 = pd.concat([idAndWeeks,df],axis="columns") frequencies = list(daysLookupDict.keys()) for freq in frequencies: rowsToToggle = int(daysLookupDict[freq]["Days of use"]/7) frequencyRowSelector = df1.Frequency==freq for row in range(0,rowsToToggle): skipNum = rowsToToggle startNum = row everyNthRowSelector = df1.index.isin(df1.index[startNum::skipNum]) columnsToSetSelector = list(weekNumbers.keys())[startNum::skipNum] print("rows to select \n", everyNthRowSelector) print("columns to select \n", columnsToSetSelector) df1.loc[frequencyRowSelector & everyNthRowSelector,columnsToSetSelector]=True print("df1"+freq+"just weeks and frequencyAFTER CHANGE: \n",df1.loc[df1.Frequency==freq,weeksAndFrequency].head()) def display_this_week(): print("test") # Get today's date # get week number of today's date # get items that are applicable to today's week. # get all weekly items # get half of bi weekly items # get 1/4 of monthly items # get 1/13 of quarterly items # get week number of arbitrary date (or each week throughout year) # get items applicable. Make sure each item is "Got" on correct cadence
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question