I am currently a beginning programmer working on a project to write and deploy a specific behavioral latency calculation online such that the app can accommodate any dataframe uploaded via CSV. The analysis requires that I take the mean of N number of columns within-person(i.e., within the same row) and iterate across all the respondents.
How can I take the specific instance where I perform this calculation, and turn it into a general function such that they apply more generally to any dataframe uploaded. For example, how can the row-based mean calculation below be written to work on N number of attributes/columns:
data['PersonalAverage'] = (data[[2]] + data[[4]] + data[[6]] + data[[8]] + data[[10]] + data[[12]] + data[[14]] + data[[16]] + data[[18]] + data[[20]] + data[[22]] + data[[24]] + data[[26]] + data[[28]] + data[[30]] + data[[32]] + data[[34]])/17
What if I uploaded a CSV with only 5 attributes (instead of 17).
Can anyone point me in the right direction?