-
Notifications
You must be signed in to change notification settings - Fork 0
/
census_view.py
72 lines (54 loc) · 1.69 KB
/
census_view.py
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
# Create a CensusView
import colony.models
import pandas
rec_l = []
mouse_df_l = []
for cage in colony.models.Cage.objects.all():
for mouse in cage.mouse_set.all():
rec_l.append({
'cage': cage.name,
'proprietor': cage.proprietor,
'mouse': mouse.name,
'sex': mouse.sex,
'dob': mouse.dob,
})
mouse_df = pandas.DataFrame.from_records(rec_l)
mouse_df_print = mouse_df.copy()
mouse_df_print.loc[
mouse_df.cage == mouse_df.cage.shift(),
'cage'] = ''
mouse_df_print.loc[
mouse_df.cage == mouse_df.cage.shift(),
'proprietor'] = ''
mouse_df_lines = mouse_df_print.to_string(header=False, index=False).split('\n')
for cage, subdf in mouse_df.groupby('cage'):
for idx in subdf.index:
print mouse_df_lines[idx]
print "-----------------------------------------------"
#~ print mouse_df_print.to_string()
1/0
rec_l = []
mouse_df_l = []
for cage in colony.models.Cage.objects.all():
rec_l.append({
'name': cage.name,
'proprietor': cage.proprietor,
})
mouse_rec_l = []
for mouse in cage.mouse_set.all():
mouse_rec_l.append({
'name': mouse.name,
'sex': mouse.sex,
'genotype': mouse.genotype,
'dob': mouse.dob})
mouse_df = pandas.DataFrame.from_records(mouse_rec_l)
mouse_df_l.append(mouse_df)
cage_df = pandas.DataFrame.from_records(rec_l)
cage_df_lines = cage_df.to_string().split('\n')
cage_df_header = cage_df_lines[0]
cage_df_lines = cage_df_lines[1:]
print cage_df_header
for ncage in range(len(cage_df)):
print cage_df_lines[ncage]
print mouse_df_l[0].to_string()
print "\n"