|
7 | 7 |
|
8 | 8 | import os
|
9 | 9 | import csv
|
10 |
| - from StringIO import StringIO |
| 10 | + from pandas.compat import StringIO, BytesIO |
11 | 11 | import pandas as pd
|
12 | 12 | ExcelWriter = pd.ExcelWriter
|
13 | 13 |
|
@@ -58,6 +58,11 @@ The corresponding ``writer`` functions are object methods that are accessed like
|
58 | 58 | * :ref:`to_clipboard<io.clipboard>`
|
59 | 59 | * :ref:`to_pickle<io.pickle>`
|
60 | 60 |
|
| 61 | +.. note:: |
| 62 | + For examples that use the ``StringIO`` class, make sure you import it |
| 63 | + according to your Python version, i.e. ``from StringIO import StringIO`` for |
| 64 | + Python 2 and ``from io import StringIO`` for Python 3. |
| 65 | + |
61 | 66 | .. _io.read_csv_table:
|
62 | 67 |
|
63 | 68 | CSV & Text files
|
@@ -278,7 +283,6 @@ used as the column names:
|
278 | 283 |
|
279 | 284 | .. ipython:: python
|
280 | 285 |
|
281 |
| - from StringIO import StringIO |
282 | 286 | data = 'a,b,c\n1,2,3\n4,5,6\n7,8,9'
|
283 | 287 | print(data)
|
284 | 288 | pd.read_csv(StringIO(data))
|
@@ -327,7 +331,7 @@ result in byte strings being decoded to unicode in the result:
|
327 | 331 | .. ipython:: python
|
328 | 332 |
|
329 | 333 | data = b'word,length\nTr\xc3\xa4umen,7\nGr\xc3\xbc\xc3\x9fe,5'.decode('utf8').encode('latin-1')
|
330 |
| - df = pd.read_csv(StringIO(data), encoding='latin-1') |
| 334 | + df = pd.read_csv(BytesIO(data), encoding='latin-1') |
331 | 335 | df
|
332 | 336 | df['word'][1]
|
333 | 337 |
|
@@ -1561,8 +1565,6 @@ You can even pass in an instance of ``StringIO`` if you so desire
|
1561 | 1565 |
|
1562 | 1566 | .. ipython:: python
|
1563 | 1567 |
|
1564 |
| - from cStringIO import StringIO |
1565 |
| -
|
1566 | 1568 | with open(file_path, 'r') as f:
|
1567 | 1569 | sio = StringIO(f.read())
|
1568 | 1570 |
|
@@ -2627,7 +2629,7 @@ chunks.
|
2627 | 2629 | store.append('dfeq', dfeq, data_columns=['number'])
|
2628 | 2630 |
|
2629 | 2631 | def chunks(l, n):
|
2630 |
| - return [l[i:i+n] for i in xrange(0, len(l), n)] |
| 2632 | + return [l[i:i+n] for i in range(0, len(l), n)] |
2631 | 2633 |
|
2632 | 2634 | evens = [2,4,6,8,10]
|
2633 | 2635 | coordinates = store.select_as_coordinates('dfeq','number=evens')
|
|
0 commit comments