-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_food_groups.py
More file actions
98 lines (54 loc) · 3.43 KB
/
make_food_groups.py
File metadata and controls
98 lines (54 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/python
#mean groups based on participant ID
#need to save NDSRfiles are xls
import pandas as pd
import numpy as np
import os
from rpy2.robjects.packages import importr
import rpy2.robjects as ro
stats = importr('stats')
base = importr('base')
os.chdir('/Users/everyonelovesacatholicgirl/Desktop/fame/fame_originals')
data=pd.ExcelFile('totals.xls')
data.sheet_names
data1=data.parse('Sheet1', index_col=0)
data2=data1.reset_index()
daya4=data2.groupby(['Participant ID'])
data5=daya4.aggregate(np.sum)
data5.to_csv('collapsed_sums.csv', sep=",")
data6 = data5.ix[3:]
data6.describe()#this works on the python object
data6.to_csv('collapsed_sums_clean.csv', sep=",")
print(ro.r('fame <-read.table("collapsed_sums_clean.csv", sep=",", header=T)'))
###making food variables###
ro.r('fame<-transform(fame, fruit=FRU0100+FRU0300+FRU0400+FRU0500)')##fruit
ro.r('fame<-transform(fame, veggeies=VEG0100+VEG0200+VEG0300+VEG0600)')##veggies
ro.r('fame <- transform(fame, starchveggies = VEG0400 + VEG0450)')##starch veg
ro.r('fame <- transform(fame, fries = VEG0800)')##fried
ro.r('fame <- transform(fame, wholegrain = GRW0100+GRW0200+GRW0300+GRW0400+GRW0500+GRW0600+GRW0900)')#NO SWEET CEREAL OR COOKIES AND CAKES whole grain
ro.r('fame<-transform(fame, somewholegrain=GRS0100+GRS0200+GRS0300+GRS0400+GRS0500+GRS0600+GRS0900)')#no cereal, cookies, cakes some whole grain
ro.r('fame<-transform(fame, refinedgrain=GRR0100+GRR0200+GRR0300+GRR0400+GRR0500+GRR0600+GRR0900)')##refined, no cereal, cookies, cakes
ro.r('fame<-transform(fame, sweetcereal=GRW0700+GRS0700+GRR0700)') ##sweet cereal
ro.r('fame<-transform(fame, sweetbakedgoods=GRW0800+GRS0800+GRR0800)')## sweet baked goods
ro.r('fame<-transform(fame, snackbars=GRW1000+GRS1000+GRR1000)') ##snack bars
ro.r('fame<-transform(fame, popcorn=GRW1100+GRW1200)')##popcorn
ro.r('fame<-transform(fame, meat=MRF0100+MRF0200+MRF0300+MRL0300+MRF0400+MRL0400+MCF0200+MCL0200+MRF0500+MPF0100+MFF0100+MFL0100+MSL0100+MCF0100+MCL0100+MOF0100+FMC0200+MOF0300)')##normal meat
ro.r('fame<-transform(fame, friedmeat=MFF0200+MSF0100+MPF0200)')##fried meat
ro.r('fame<-transform(fame, nuts=MOF0500+MOF0600)') ##nuts
ro.r('fame<-transform(fame, fakemeat=MOF0700)')## fake meat
ro.r('fame<-transform(fame, milk=DMF0100+DMR0100+DML0100+DMN0100)') #white milk
ro.r('fame<-transform(fame, flavoredmilk=DMF0200+DMR0200+DML0200+DML0300)') #sweet milk
ro.r('fame<-transform(fame, cheese=DCF0100+DCR0100+DCL0100+DCN0100)')## cheese
ro.r('fame<-transform(fame, sweetyogurt=DYF0100+DYR0100+DYL0100)')## sweetyogurt
ro.r('fame<-transform(fame, yogurt=DYF0200+DYR0200+DYL0200+DYN0100)')##plain yogurt
ro.r('fame<-transform(fame, deserts=DOT0100+DOT0200+DOT0300+SWT0400+SWT0500+SWT0700+SWT0800+SWT0200+SWT0300+MSC0600)')## deserts
ro.r('fame<-transform(fame,cream=FCF0100+FCR0100+FCN0100)')## cream
ro.r('fame<-transform(fame, fats=FMF0100+FMR0100+FOF0100+FAF0100+FSF0100+FAR0100+FDF0100+FDR0100)') ##fats
ro.r('fame<-transform(fame, SSB=BVS0400+BVS0300+BVS0500+BVS0100+BVS0200+BVS0600)') ##SSB
ro.r('fame<-transform(fame, artSSB=BVA0400+BVU0300+BVA0300+BVA0500+BVU0400+BVA0100+BVA0200+BVU0200+BVA0600+BVU0500)') ##artifical SSB
ro.r('fame<-transform(fame, condiments=MSC0200+MSC0300+MSC0400)') ##condiments
###making categorical variables###
ro.r('fame$ssbcat[fame$SSB<1]<-0') #low
ro.r('fame$ssbcat[fame$SSB<=1 & fame$SSB<2]<-1') #med
ro.r('fame$ssbcat[fame$SSB>=2]<-2') #high
ro.r('write.table(fame, "calculated.csv", sep=",", row.names=FALSE)')