Skip to content

Commit d331886

Browse files
committed
big refactor, added example and test subdirectories, got rid of old test codes
1 parent 72d1ba4 commit d331886

File tree

9 files changed

+562
-59
lines changed

9 files changed

+562
-59
lines changed
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {
7+
"collapsed": true
8+
},
9+
"outputs": [],
10+
"source": [
11+
"import pandas\n",
12+
"import numpy as np\n",
13+
"filename = 'people.txt'"
14+
]
15+
},
16+
{
17+
"cell_type": "code",
18+
"execution_count": 2,
19+
"metadata": {
20+
"collapsed": false
21+
},
22+
"outputs": [],
23+
"source": [
24+
"peopledf = pandas.read_csv(filename)\n",
25+
"peopledf2 = pandas.read_csv(filename)\n",
26+
"peopledf3 = pandas.read_csv(filename)"
27+
]
28+
},
29+
{
30+
"cell_type": "code",
31+
"execution_count": 3,
32+
"metadata": {
33+
"collapsed": false
34+
},
35+
"outputs": [
36+
{
37+
"name": "stdout",
38+
"output_type": "stream",
39+
"text": [
40+
"Mr. and Mrs. Amal Aditya\n",
41+
"Mr. and Mrs. John Martone\n",
42+
"Mr. and Mrs. Philip Veli\n",
43+
"Mr. and Mrs. Mark Gruber\n",
44+
"Mr. and Mrs. John Giudice\n",
45+
"Mr. and Mrs. John Giudice \n",
46+
"Mr. and Mrs. Salvatore Veli\n",
47+
"Mr. and Mrs. Joseph Tardibuono\n",
48+
"Mr. and Mrs. Ronald Teicher\n",
49+
"Mr. and Mrs. Thomas Cannizzo\n",
50+
"Mr. and Mrs. Paul Mastromarino\n",
51+
"Mr. and Mrs. Bartolo Iozzia\n",
52+
"Mr. and Mrs. Emanuele Brugaletta\n",
53+
"Mr. and Mrs. Joseph Marinelli\n"
54+
]
55+
}
56+
],
57+
"source": [
58+
"#Split couples\n",
59+
"for rownum in peopledf.index:\n",
60+
" guestname = peopledf.iloc[rownum]['Guest Name']\n",
61+
" if \"Mr. and Mrs.\" in guestname:\n",
62+
" print guestname\n",
63+
" splits = guestname.split(' ')\n",
64+
" peopledf2.iloc[rownum]['Guest Name'] = splits[0]+\" \"+\" \".join(splits[3:])\n",
65+
" peopledf2.iloc[rownum]['friend1'] = splits[2]+\" \"+\" \".join(splits[3:])"
66+
]
67+
},
68+
{
69+
"cell_type": "code",
70+
"execution_count": 4,
71+
"metadata": {
72+
"collapsed": false
73+
},
74+
"outputs": [
75+
{
76+
"name": "stdout",
77+
"output_type": "stream",
78+
"text": [
79+
"Mr. Marc Veli and Guest\n",
80+
"Mr. Marc Veli\n",
81+
"Mr. David Giudice and Guest\n",
82+
"Mr. David Giudice\n",
83+
"Ms. Danielle Veli and Guest\n",
84+
"Ms. Danielle Veli\n",
85+
"Mr. John Brugaletta and Guest\n",
86+
"Mr. John Brugaletta\n",
87+
"Ms. Josephine Rovetto and Guest\n",
88+
"Ms. Josephine Rovetto\n",
89+
"Rick and guest\n",
90+
"Rick\n",
91+
"james peterson and guest\n",
92+
"james peterson\n",
93+
"steve royce and guest\n",
94+
"steve royce\n"
95+
]
96+
}
97+
],
98+
"source": [
99+
"#Split people and their guest\n",
100+
"for rownum in peopledf.index:\n",
101+
" guestname = peopledf.iloc[rownum]['Guest Name']\n",
102+
" if \" and guest\" in guestname.lower():\n",
103+
" print guestname\n",
104+
" splits = guestname.split(' ')\n",
105+
" print \" \".join(splits[:-2])\n",
106+
" peopledf2.iloc[rownum]['Guest Name'] = \" \".join(splits[:-2])\n",
107+
" peopledf2.iloc[rownum]['friend1'] = \" \".join(splits[:-2])+\"'s guest\""
108+
]
109+
},
110+
{
111+
"cell_type": "code",
112+
"execution_count": 9,
113+
"metadata": {
114+
"collapsed": false
115+
},
116+
"outputs": [
117+
{
118+
"name": "stdout",
119+
"output_type": "stream",
120+
"text": [
121+
"Melissa Rovetto and David Ruffner\n",
122+
"DJ and Mcee\n",
123+
"Mary Margaret and Ben Molnar\n"
124+
]
125+
}
126+
],
127+
"source": [
128+
"#Split people\n",
129+
"for rownum in peopledf2.index:\n",
130+
" guestname = peopledf2.iloc[rownum]['Guest Name']\n",
131+
" if \" and \" in guestname.lower():\n",
132+
" print guestname\n",
133+
" splits = guestname.split(' and ')\n",
134+
" peopledf2.iloc[rownum]['Guest Name'] = splits[0]\n",
135+
" peopledf2.iloc[rownum]['friend1'] = splits[1]"
136+
]
137+
},
138+
{
139+
"cell_type": "code",
140+
"execution_count": 10,
141+
"metadata": {
142+
"collapsed": false
143+
},
144+
"outputs": [],
145+
"source": [
146+
"#Clean out end lines\n",
147+
"for column in peopledf2[1:]:\n",
148+
" for rownum in peopledf2.index:\n",
149+
" name = peopledf2.iloc[rownum][column]\n",
150+
" #print rownum, column, name\n",
151+
" if name is np.nan:\n",
152+
" continue\n",
153+
" name = name.strip()\n",
154+
" if \"\\n\" in name:\n",
155+
" name = name.translate(None,'\\n')\n",
156+
" peopledf3.iloc[rownum][column] = name\n",
157+
"# peopledf2.iloc[rownum]['Guest Name'] = \" \".join(splits[:-2])\n",
158+
"# peopledf2.iloc[rownum]['friend1'] = \" \".join(splits[:-2])+\"'s guest\""
159+
]
160+
},
161+
{
162+
"cell_type": "code",
163+
"execution_count": 11,
164+
"metadata": {
165+
"collapsed": false
166+
},
167+
"outputs": [],
168+
"source": [
169+
"peopledf3.to_excel('people6.xlsx')"
170+
]
171+
},
172+
{
173+
"cell_type": "code",
174+
"execution_count": null,
175+
"metadata": {
176+
"collapsed": true
177+
},
178+
"outputs": [],
179+
"source": []
180+
}
181+
],
182+
"metadata": {
183+
"kernelspec": {
184+
"display_name": "Python 2",
185+
"language": "python",
186+
"name": "python2"
187+
},
188+
"language_info": {
189+
"codemirror_mode": {
190+
"name": "ipython",
191+
"version": 2
192+
},
193+
"file_extension": ".py",
194+
"mimetype": "text/x-python",
195+
"name": "python",
196+
"nbconvert_exporter": "python",
197+
"pygments_lexer": "ipython2",
198+
"version": "2.7.10"
199+
}
200+
},
201+
"nbformat": 4,
202+
"nbformat_minor": 0
203+
}

0 commit comments

Comments
 (0)