Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I am able to read a file, but not able to see the result on Google Colab

df01 = pd.read_json('/content/drive/MyDrive/project/rio_bq_2019000000000000',lines=True)

No error for this line. But it has error on next line, I don't understand what happens here. I read it on google colab

df01

I got an error as following:

AttributeError                            Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/IPython/core/formatters.py in __call__(self, obj)
    336             method = get_real_method(obj, self.print_method)
    337             if method is not None:
--> 338                 return method()
    339             return None
    340         else:

1 frames
/usr/local/lib/python3.7/dist-packages/pandas/io/formats/format.py in to_html(self, buf, encoding, classes, notebook, border)
    986         notebook : {True, False}, optional, default False
    987             Whether the generated HTML is for IPython Notebook.
--> 988         border : int
    989             A ``border=border`` attribute is included in the opening
    990             ``<table>`` tag. Default ``pd.options.display.html.border``.

AttributeError: 'NotebookFormatter' object has no attribute 'get_result'
        Building    Level  ...        lng                    localtime
0           TPS1  Level 2  ... -43.249902  2019-08-01 02:52:33.289 UTC
1           TPS1  Level 2  ... -43.250474  2019-08-01 02:52:35.488 UTC
2           TPS1  Level 2  ... -43.251573  2019-08-01 02:52:36.268 UTC
3           TPS1  Level 2  ... -43.249719  2019-08-01 02:52:41.537 UTC
4           TPS1  Level 2  ... -43.249737  2019-08-01 02:52:41.538 UTC
...          ...      ...  ...        ...                          ...
3372900     TPS1  Level 2  ... -43.250513  2019-08-25 10:21:01.483 UTC
3372901     TPS1  Level 2  ... -43.250169  2019-08-25 10:21:02.024 UTC
3372902     TPS1  Level 2  ... -43.250169  2019-08-25 10:21:02.026 UTC
3372903     TPS1  Level 2  ... -43.249944  2019-08-25 10:21:02.536 UTC
3372904     TPS1  Level 2  ... -43.249944  2019-08-25 10:21:02.536 UTC

I can see the data is imported in df01 as shown in the bottom of error output. But I can't use it. Why? how can I fix this?

In case you need, this is my sample data file

 {"Building":"TPS2","Level":"Level 3","ClientMacAddr":"8c:8e:f2:7d:2f:de","lat":-22.813377029213196,"lng":-43.247283256092494,"localtime":"2019-11-28 17:49:00.753 UTC"}
{"Building":"TPS2","Level":"Level 3","ClientMacAddr":"8c:8e:f2:7d:2f:de","lat":-22.813377029213196,"lng":-43.247283256092494,"localtime":"2019-11-28 17:49:00.753 UTC"}
{"Building":"TPS2","Level":"Level 3","ClientMacAddr":"00:27:15:00:10:1f","lat":-22.814628521677054,"lng":-43.24741506118599,"localtime":"2019-11-28 17:49:01.58 UTC"}
{"Building":"TPS2","Level":"Level 3","ClientMacAddr":"00:27:15:00:10:1f","lat":-22.814628521677054,"lng":-43.24741506118599,"localtime":"2019-11-28 17:49:01.58 UTC"}

I only have two lines before this

import pandas as pd
drive.mount("/content/drive")
like image 252
AlexWithYou Avatar asked Feb 28 '21 18:02

AlexWithYou


People also ask

How do I read a file from Google Drive Colab?

Once the Drive is mounted, you'll get the message “Mounted at /content/gdrive” , and you'll be able to browse through the contents of your Drive from the file-explorer pane. Now you can interact with your Google Drive as if it was a folder in your Colab environment.

How do I see local files on Google Colab?

2) From a local drive Click on “Choose Files” then select and upload the file. Wait for the file to be 100% uploaded. You should see the name of the file once Colab has uploaded it. Finally, type in the following code to import it into a dataframe (make sure the filename matches the name of the uploaded file).

How do I read dataset in Google Colab?

From Github It is the easiest way to upload a CSV file in Colab. For this go to the dataset in your GitHub repository, and then click on “View Raw”.


1 Answers

I still don't know what happened. But I just figure out myself

I can only make output in this case with print

Like df01 works well in jupyter, but in google lab I can only write in print(df01)

If you meet with this error

AttributeError: 'NotebookFormatter' object has no attribute 'get_result'

Please add print() in each line you are making an output

like image 50
AlexWithYou Avatar answered Oct 27 '22 01:10

AlexWithYou