Antoni Parellada
Antoni Parellada

Reputation: 4791

Error message with imported csv file as a pandas DataFrame in Google Colab

The code used is

import pandas as pd
url = 'https://raw.githubusercontent.com/RInterested/datasets/gh-pages/mtcars.csv'
dataframe = pd.read_csv(url)
isinstance(dataframe, pd.DataFrame) # This lets me know the data is successfully imported as a DF.
dataframe.head()

But is this last line the spits out an unexpected error:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
/usr/local/lib/python3.6/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.6/dist-packages/pandas/io/formats/format.py in to_html(self, buf, encoding, classes, notebook, border)
    977             if (i >= nlevels and self.fmt.index and self.multirow and
    978                     ilevels > 1):
--> 979                 # sum up rows to multirows
    980                 crow = self._format_multirow(crow, ilevels, i, strrows)
    981             buf.write(' & '.join(crow))

ModuleNotFoundError: No module named 'pandas.io.formats.html'

The suggested SO question to resolve the issue deals with the error:

ModuleNotFoundError: No module named 'pandas.io.formats.csvs'

which seems different.

Upvotes: 3

Views: 1282

Answers (1)

Protik Nag
Protik Nag

Reputation: 529

It's working for me. Maybe you need to update your python. But here is an alternative solution. Try this:

import pandas as pd
import io
import requests

url = "https://raw.githubusercontent.com/RInterested/datasets/gh-pages/mtcars.csv"
contents = requests.get(url).content
df = pd.read_csv(io.StringIO(contents.decode('utf-8')))
isinstance(df, pd.DataFrame) 
df.head()

I hope this will work fine. :)

Upvotes: 1

Related Questions