chintan s chintan s - 2 months ago 12
Python Question

Pandas: How to open certain files

I am currently working on the data set from this link. But I am unable to read these files from Pandas? Has anyone tried to play with such files?

I am trying the following:

import pandas as pd

df = pd.read_csv("m_4549381c276b46c6.0000")


But I get the following error

Error tokenizing data. C error: Buffer overflow caught - possible malformed input file.

Answer

Those files are parts of a saved SFrame.

So you can load them this way:

import sframe

sf = sframe.SFrame('/path/to/dir/')

Demo: I've downloaded all files from people_wiki.gl and put them under: D:/download/sframe/

In [7]: import sframe

In [7]: sf = sframe.SFrame('D:/download/sframe/')

In [8]: sf
Out[8]:
Columns:
        URI     str
        name    str
        text    str

Rows: 59071

Data:
+-------------------------------+---------------------+
|              URI              |         name        |
+-------------------------------+---------------------+
| <http://dbpedia.org/resour... |    Digby Morrell    |
| <http://dbpedia.org/resour... |    Alfred J. Lewy   |
| <http://dbpedia.org/resour... |    Harpdog Brown    |
| <http://dbpedia.org/resour... | Franz Rottensteiner |
| <http://dbpedia.org/resour... |        G-Enka       |
| <http://dbpedia.org/resour... |    Sam Henderson    |
| <http://dbpedia.org/resour... |    Aaron LaCrate    |
| <http://dbpedia.org/resour... |   Trevor Ferguson   |
| <http://dbpedia.org/resour... |     Grant Nelson    |
| <http://dbpedia.org/resour... |     Cathy Caruth    |
+-------------------------------+---------------------+
+-------------------------------+
|              text             |
+-------------------------------+
| digby morrell born 10 octo... |
| alfred j lewy aka sandy le... |
| harpdog brown is a singer ... |
| franz rottensteiner born i... |
| henry krvits born 30 decem... |
| sam henderson born october... |
| aaron lacrate is an americ... |
| trevor ferguson aka john f... |
| grant nelson born 27 april... |
| cathy caruth born 1955 is ... |
+-------------------------------+
[59071 rows x 3 columns]
Note: Only the head of the SFrame is printed.
You can use print_rows(num_rows=m, num_columns=n) to print more rows and columns.

Now you can convert it to Pandas DF if you need:

In [17]: df = sf.to_dataframe()

In [18]: pd.options.display.max_colwidth = 40

In [19]: df.head()
Out[19]:
                                       URI                 name                                     text
0  <http://dbpedia.org/resource/Digby_M...        Digby Morrell  digby morrell born 10 october 1979 i...
1  <http://dbpedia.org/resource/Alfred_...       Alfred J. Lewy  alfred j lewy aka sandy lewy graduat...
2  <http://dbpedia.org/resource/Harpdog...        Harpdog Brown  harpdog brown is a singer and harmon...
3  <http://dbpedia.org/resource/Franz_R...  Franz Rottensteiner  franz rottensteiner born in waidmann...
4     <http://dbpedia.org/resource/G-Enka>               G-Enka  henry krvits born 30 december 1974 i...

In [20]: df.shape
Out[20]: (59071, 3)