I've been searching for honestly a couple weeks for an answer to this question and haven't yet found one - my search history is downright shameful at this point. That said, I'm quite new to Python (and programming in general), so it's certainly possible that I simply am not phrasing my question correctly and it's been answered before - I apologize if that's the case.
I'm attempting to create a list when a function is run that uses a parameter from the function in the created list's name, but I'm having no luck.
Sample of data used:
Station Date Tmax Tmin Tavg DewPoint WetBulb Heat CodeSum PrecipTotal ... Mist Haze Rain Thunderstorm Fog Patches Drizzle Smoke Squall NoLoggedCodes
0 1 5/1/2007 83 50 67 51 56 0 NO 0.0 ... 0 0 0 0 0 0 0 0 0 1
1 1 5/2/2007 59 42 51 42 47 14 BR 0.0 ... 1 0 0 0 0 0 0 0 0 0
2 1 5/3/2007 66 46 56 40 48 9 NO 0.0 ... 0 0 0 0 0 0 0 0 0 1
3 1 5/4/2007 66 49 58 41 50 7 RA 0.0 ... 0 0 1 0 0 0 0 0 0 0
4 1 5/5/2007 66 53 60 38 49 5 NO 0.0 ... 0 0 0 0 0 0 0 0 0 1
I know what's shown in the following is the wrong syntax, but hopefully it gives an idea of what I'm attempting. The function itself (outside of the added syntax errors) works fine for its purpose, but my goal is to have it also create a list of the new columns that were created and ideally follows the naming convention shown below. Any ideas how I can accomplish that?
def rollingfunction(days):
"""creates new rolling mean columns for each weather station for each item in list Keys"""
WeatherCon{days}Day = [] #this line is incorrect, but I hope gives an idea of my goal
for x in Keys:
Station1[f'Last{days}DayAvg{x}'] Station1[x].rolling(days).mean()
Station2[f'Last{days}DayAvg{x}'] Station2[x].rolling(days).mean()
WeatherCon{days}Day.append([f'Last{days}DayAvg{x}']) #this line is also incorrect, but again context
#this is the list and list name that I want to create when the function is run with a call of 5.
#This list is simply the names of the new columns created by the function so I can reference these columns later.
WeatherCon5Day = ['Last5DayAvgHaze', 'Last5DayAvgPrecipTotal', 'Last5DayAvgThunderstorm', 'Last5DayAvgFog', 'Last5DayAvgPatches', 'Last5DayAvgSmoke', 'Last5DayAvgSquall', 'Last5DayAvgNoLoggedCodes', 'Last5DayAvgTavg', 'Last5DayAvgAvgSpeed', 'Last5DayAvgDewPoint']
When the function is called for 5, it returns new individual columns for each weather pattern in Keys.
Presently, I'm using these new columns to perform a regression to mosquito growth
Ideally, my end goal is to be able to perform regressions on all weather values to mosquito population growth for every length of days up to around 15-20 and then use that to create a line graph showing coef and P-values over time to highlight when each value has the most (if any) effect. Obviously, calling rollingfunction() 15+ times and manually creating 15+ lists to use to get the needed regression values is silly, error prone, and just ugly. Additionally, I also recognize that what I'm attempting would create over 100 new columns and may also be quite silly.
I'd really appreciate any help y'all could give - even just pointing me in the right way. Thanks so much!