-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString splitter.py
More file actions
355 lines (337 loc) · 17.7 KB
/
Copy pathString splitter.py
File metadata and controls
355 lines (337 loc) · 17.7 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
Python 3.6.1 |Continuum Analytics, Inc.| (default, May 11 2017, 13:04:09)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> WARNING: The version of Tcl/Tk (8.5.9) in use may be unstable.
Visit http://www.python.org/download/mac/tcltk/ for current information.
X = ["I sell seashells by the seashore.","She sells seashells by the seashore."]
>>> import pandas as pd
>>> X_pd = pd.Series(X)
>>> X_pd
0 I sell seashells by the seashore.
1 She sells seashells by the seashore.
dtype: object
>>> X_pd.get_dummies()
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
X_pd.get_dummies()
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/generic.py", line 3614, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'get_dummies'
>>> pd.get_dummies(X_pd)
I sell seashells by the seashore. She sells seashells by the seashore.
0 1 0
1 0 1
>>> pd.get_dummies(X_pd[0])
I sell seashells by the seashore.
0 1
>>> pd.get_dummies(X_pd.str.split(" "))
Traceback (most recent call last):
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/categorical.py", line 330, in __init__
codes, categories = factorize(values, sort=True)
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/algorithms.py", line 471, in factorize
labels = table.get_labels(values, uniques, 0, na_sentinel, check_nulls)
File "pandas/_libs/hashtable_class_helper.pxi", line 1367, in pandas._libs.hashtable.PyObjectHashTable.get_labels
TypeError: unhashable type: 'list'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
pd.get_dummies(X_pd.str.split(" "))
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/reshape/reshape.py", line 1215, in get_dummies
sparse=sparse, drop_first=drop_first)
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/reshape/reshape.py", line 1222, in _get_dummies_1d
codes, levels = _factorize_from_iterable(Series(data))
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/categorical.py", line 2324, in _factorize_from_iterable
cat = Categorical(values, ordered=True)
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/categorical.py", line 332, in __init__
codes, categories = factorize(values, sort=False)
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/algorithms.py", line 471, in factorize
labels = table.get_labels(values, uniques, 0, na_sentinel, check_nulls)
File "pandas/_libs/hashtable_class_helper.pxi", line 1367, in pandas._libs.hashtable.PyObjectHashTable.get_labels
TypeError: unhashable type: 'list'
>>> pd.get_dummies(X_pd[0].str.split(" "))
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
pd.get_dummies(X_pd[0].str.split(" "))
AttributeError: 'str' object has no attribute 'str'
>>> X_pd
0 I sell seashells by the seashore.
1 She sells seashells by the seashore.
dtype: object
>>> pd.get_dummies(X_pd.str.split(" "))
Traceback (most recent call last):
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/categorical.py", line 330, in __init__
codes, categories = factorize(values, sort=True)
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/algorithms.py", line 471, in factorize
labels = table.get_labels(values, uniques, 0, na_sentinel, check_nulls)
File "pandas/_libs/hashtable_class_helper.pxi", line 1367, in pandas._libs.hashtable.PyObjectHashTable.get_labels
TypeError: unhashable type: 'list'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
pd.get_dummies(X_pd.str.split(" "))
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/reshape/reshape.py", line 1215, in get_dummies
sparse=sparse, drop_first=drop_first)
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/reshape/reshape.py", line 1222, in _get_dummies_1d
codes, levels = _factorize_from_iterable(Series(data))
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/categorical.py", line 2324, in _factorize_from_iterable
cat = Categorical(values, ordered=True)
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/categorical.py", line 332, in __init__
codes, categories = factorize(values, sort=False)
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/algorithms.py", line 471, in factorize
labels = table.get_labels(values, uniques, 0, na_sentinel, check_nulls)
File "pandas/_libs/hashtable_class_helper.pxi", line 1367, in pandas._libs.hashtable.PyObjectHashTable.get_labels
TypeError: unhashable type: 'list'
>>> Y = X_pd.str.split(" ")
>>> Y
0 [I, sell, seashells, by, the, seashore.]
1 [She, sells, seashells, by, the, seashore.]
dtype: object
>>> type(Y)
<class 'pandas.core.series.Series'>
>>> pd.DataFrame(Y)
0
0 [I, sell, seashells, by, the, seashore.]
1 [She, sells, seashells, by, the, seashore.]
>>> pd.get_dummies(Y)
Traceback (most recent call last):
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/categorical.py", line 330, in __init__
codes, categories = factorize(values, sort=True)
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/algorithms.py", line 471, in factorize
labels = table.get_labels(values, uniques, 0, na_sentinel, check_nulls)
File "pandas/_libs/hashtable_class_helper.pxi", line 1367, in pandas._libs.hashtable.PyObjectHashTable.get_labels
TypeError: unhashable type: 'list'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#15>", line 1, in <module>
pd.get_dummies(Y)
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/reshape/reshape.py", line 1215, in get_dummies
sparse=sparse, drop_first=drop_first)
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/reshape/reshape.py", line 1222, in _get_dummies_1d
codes, levels = _factorize_from_iterable(Series(data))
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/categorical.py", line 2324, in _factorize_from_iterable
cat = Categorical(values, ordered=True)
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/categorical.py", line 332, in __init__
codes, categories = factorize(values, sort=False)
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/algorithms.py", line 471, in factorize
labels = table.get_labels(values, uniques, 0, na_sentinel, check_nulls)
File "pandas/_libs/hashtable_class_helper.pxi", line 1367, in pandas._libs.hashtable.PyObjectHashTable.get_labels
TypeError: unhashable type: 'list'
>>> pd.get_dummies(Y[1])
She by seashells seashore. sells the
0 1 0 0 0 0 0
1 0 0 0 0 1 0
2 0 0 1 0 0 0
3 0 1 0 0 0 0
4 0 0 0 0 0 1
5 0 0 0 1 0 0
>>> Y[1]
['She', 'sells', 'seashells', 'by', 'the', 'seashore.']
>>> pd.get_dummies
<function get_dummies at 0x10dfe1ea0>
>>> pd.apply(get_dummies(Y))
Traceback (most recent call last):
File "<pyshell#19>", line 1, in <module>
pd.apply(get_dummies(Y))
AttributeError: module 'pandas' has no attribute 'apply'
>>> Y.apply(get_dummies)
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
Y.apply(get_dummies)
NameError: name 'get_dummies' is not defined
>>> Y.apply(pd.get_dummies)
0 I by seashells seashore. sell the
0 1...
1 She by seashells seashore. sells the
0...
dtype: object
>>> ohe = Y.apply(pd.get_dummies)
>>> ohe
0 I by seashells seashore. sell the
0 1...
1 She by seashells seashore. sells the
0...
dtype: object
>>> from ipython import display
Traceback (most recent call last):
File "<pyshell#24>", line 1, in <module>
from ipython import display
ModuleNotFoundError: No module named 'ipython'
>>> from IPython import display
>>> display(ohe)
Traceback (most recent call last):
File "<pyshell#26>", line 1, in <module>
display(ohe)
TypeError: 'module' object is not callable
>>> display.display(ohe)
0 I by seashells seashore. sell the
0 1...
1 She by seashells seashore. sells the
0...
dtype: object
>>> X = [["Do you sell seashells by the seashore?","Does she sell seashells by the seashore?"],["I sell seashells by the seashore.","She sells seashells by the seashore."]]
>>> X
[['Do you sell seashells by the seashore?', 'Does she sell seashells by the seashore?'], ['I sell seashells by the seashore.', 'She sells seashells by the seashore.']]
>>> nparray(X)
Traceback (most recent call last):
File "<pyshell#30>", line 1, in <module>
nparray(X)
NameError: name 'nparray' is not defined
>>> pd.DataFrame(X)
0 \
0 Do you sell seashells by the seashore?
1 I sell seashells by the seashore.
1
0 Does she sell seashells by the seashore?
1 She sells seashells by the seashore.
>>> X = [["Do you sell seashells by the seashore","I sell seashells by the seashore"],["Does she sell seashells by the seashore","She sells seashells by the seashore"]]
>>> pd.DataFrame(X)
0 \
0 Do you sell seashells by the seashore
1 Does she sell seashells by the seashore
1
0 I sell seashells by the seashore
1 She sells seashells by the seashore
>>> Y = pd.DataFrame(X).str.split(" ")
Traceback (most recent call last):
File "<pyshell#34>", line 1, in <module>
Y = pd.DataFrame(X).str.split(" ")
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/generic.py", line 3614, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'str'
>>> X_pd = pd.DataFrame(X)
>>> X_pd.str.split(" ")
Traceback (most recent call last):
File "<pyshell#36>", line 1, in <module>
X_pd.str.split(" ")
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/generic.py", line 3614, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'str'
>>> Y_pd = X[0:2].str.split(" ")
Traceback (most recent call last):
File "<pyshell#37>", line 1, in <module>
Y_pd = X[0:2].str.split(" ")
AttributeError: 'list' object has no attribute 'str'
>>> X[0:2]
[['Do you sell seashells by the seashore', 'I sell seashells by the seashore'], ['Does she sell seashells by the seashore', 'She sells seashells by the seashore']]
>>> X["0"]
Traceback (most recent call last):
File "<pyshell#39>", line 1, in <module>
X["0"]
TypeError: list indices must be integers or slices, not str
>>> X[:2]
[['Do you sell seashells by the seashore', 'I sell seashells by the seashore'], ['Does she sell seashells by the seashore', 'She sells seashells by the seashore']]
>>> pd.Series(X).str.split(" ")
0 NaN
1 NaN
dtype: float64
>>> X.apply(lambda row: pd.get_dummies(row))
Traceback (most recent call last):
File "<pyshell#42>", line 1, in <module>
X.apply(lambda row: pd.get_dummies(row))
AttributeError: 'list' object has no attribute 'apply'
>>> X_pd.apply(lambda row: pd.get_dummies(row))
0 \
0 (D, o, , y, o, u, , s, e, l, l, , s, e, a, ...
1 (D, o, e, s, , s, h, e, , s, e, l, l, , s, ...
1
0 (I, , s, e, l, l, , s, e, a, s, h, e, l, l, ...
1 (S, h, e, , s, e, l, l, s, , s, e, a, s, h, ...
>>> X_pd
0 \
0 Do you sell seashells by the seashore
1 Does she sell seashells by the seashore
1
0 I sell seashells by the seashore
1 She sells seashells by the seashore
>>> X_pd.applymap(lambda row: pd.get_dummies(row))
0 \
0 Do you sell seashells by the seashore
0 ...
1 Does she sell seashells by the seashore
0 ...
1
0 I sell seashells by the seashore
0 ...
1 She sells seashells by the seashore
0 ...
>>> X_pd.apply(lambda x: type(x))
0 <class 'pandas.core.series.Series'>
1 <class 'pandas.core.series.Series'>
dtype: object
>>> X_pd.apply(lambda row: pd.get_dummies(row.str.split(" ")))
Traceback (most recent call last):
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/categorical.py", line 330, in __init__
codes, categories = factorize(values, sort=True)
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/algorithms.py", line 471, in factorize
labels = table.get_labels(values, uniques, 0, na_sentinel, check_nulls)
File "pandas/_libs/hashtable_class_helper.pxi", line 1367, in pandas._libs.hashtable.PyObjectHashTable.get_labels
TypeError: unhashable type: 'list'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#47>", line 1, in <module>
X_pd.apply(lambda row: pd.get_dummies(row.str.split(" ")))
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/frame.py", line 4877, in apply
ignore_failures=ignore_failures)
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/frame.py", line 4973, in _apply_standard
results[i] = func(v)
File "<pyshell#47>", line 1, in <lambda>
X_pd.apply(lambda row: pd.get_dummies(row.str.split(" ")))
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/reshape/reshape.py", line 1215, in get_dummies
sparse=sparse, drop_first=drop_first)
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/reshape/reshape.py", line 1222, in _get_dummies_1d
codes, levels = _factorize_from_iterable(Series(data))
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/categorical.py", line 2324, in _factorize_from_iterable
cat = Categorical(values, ordered=True)
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/categorical.py", line 332, in __init__
codes, categories = factorize(values, sort=False)
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/algorithms.py", line 471, in factorize
labels = table.get_labels(values, uniques, 0, na_sentinel, check_nulls)
File "pandas/_libs/hashtable_class_helper.pxi", line 1367, in pandas._libs.hashtable.PyObjectHashTable.get_labels
TypeError: ("unhashable type: 'list'", 'occurred at index 0')
>>> X_pd.apply(lambda row: row.str.split(" "))
0 \
0 [Do, you, sell, seashells, by, the, seashore]
1 [Does, she, sell, seashells, by, the, seashore]
1
0 [I, sell, seashells, by, the, seashore]
1 [She, sells, seashells, by, the, seashore]
>>> Y = X_pd.apply(lambda row: row.str.split(" "))
>>> Y
0 \
0 [Do, you, sell, seashells, by, the, seashore]
1 [Does, she, sell, seashells, by, the, seashore]
1
0 [I, sell, seashells, by, the, seashore]
1 [She, sells, seashells, by, the, seashore]
>>> pd.get_dummies(Y)
Traceback (most recent call last):
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/categorical.py", line 330, in __init__
codes, categories = factorize(values, sort=True)
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/algorithms.py", line 471, in factorize
labels = table.get_labels(values, uniques, 0, na_sentinel, check_nulls)
File "pandas/_libs/hashtable_class_helper.pxi", line 1367, in pandas._libs.hashtable.PyObjectHashTable.get_labels
TypeError: unhashable type: 'list'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#51>", line 1, in <module>
pd.get_dummies(Y)
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/reshape/reshape.py", line 1210, in get_dummies
drop_first=drop_first)
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/reshape/reshape.py", line 1222, in _get_dummies_1d
codes, levels = _factorize_from_iterable(Series(data))
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/categorical.py", line 2324, in _factorize_from_iterable
cat = Categorical(values, ordered=True)
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/categorical.py", line 332, in __init__
codes, categories = factorize(values, sort=False)
File "/Users/montana/miniconda3/lib/python3.6/site-packages/pandas/core/algorithms.py", line 471, in factorize
labels = table.get_labels(values, uniques, 0, na_sentinel, check_nulls)
File "pandas/_libs/hashtable_class_helper.pxi", line 1367, in pandas._libs.hashtable.PyObjectHashTable.get_labels
TypeError: unhashable type: 'list'
>>> X_pd
0 \
0 Do you sell seashells by the seashore
1 Does she sell seashells by the seashore
1
0 I sell seashells by the seashore
1 She sells seashells by the seashore
>>>