Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
127 views
in Technique[技术] by (71.8m points)

python 3.x - How to resolve this error when trying to use Pandas Styling?

I am running Python 3.6.5 and Pandas 0.25.2.

On attempting to style a pandas dataframe I am getting a specific error which can be generated by simplifying to this code:

import pandas as pd
import pandas.io.formats.style

The summary of the error generated is:

ImportError: The 'packaging._typing' package is required; normally this is bundled with this package so if you get this warning, consult the packager of your distribution.

The full error message is:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-e9b944578fec> in <module>()
      1 import pandas as pd
----> 2 import pandas.io.formats.style

~Anaconda3libsite-packagespandasioformatsstyle.py in <module>()
     48 
     49 
---> 50 class Styler:
     51     """
     52     Helps style a DataFrame or Series according to the data with HTML and CSS.

~Anaconda3libsite-packagespandasioformatsstyle.py in Styler()
    109     """
    110 
--> 111     loader = jinja2.PackageLoader("pandas", "io/formats/templates")
    112     env = jinja2.Environment(loader=loader, trim_blocks=True)
    113     template = env.get_template("html.tpl")

~Anaconda3libsite-packagesjinja2loaders.py in __init__(self, package_name, package_path, encoding)
    220     def __init__(self, package_name, package_path='templates',
    221                  encoding='utf-8'):
--> 222         from pkg_resources import DefaultProvider, ResourceManager, 
    223                                   get_provider
    224         provider = get_provider(package_name)

~Anaconda3libsite-packagespkg_resources\__init__.py in <module>()
     79 from pkg_resources.extern import appdirs
     80 from pkg_resources.extern import packaging
---> 81 __import__('pkg_resources.extern.packaging.version')
     82 __import__('pkg_resources.extern.packaging.specifiers')
     83 __import__('pkg_resources.extern.packaging.requirements')

~Anaconda3libsite-packagespkg_resources\_vendorpackagingversion.py in <module>()
      9 
     10 from ._structures import Infinity, NegativeInfinity
---> 11 from ._typing import TYPE_CHECKING
     12 
     13 if TYPE_CHECKING:  # pragma: no cover

~Anaconda3libsite-packagespkg_resourcesextern\__init__.py in load_module(self, fullname)
     52                 "normally this is bundled with this package so if you get "
     53                 "this warning, consult the packager of your "
---> 54                 "distribution.".format(**locals())
     55             )
     56 

I have tried reinstalling and upgrading the pandas installation, but each time I get the same error. This is being doine through an Anaconda environment.

Has anyone seen this error before? Is there a more detailed explanation that anyone can provide in an effort to solve this issue so that I can get the pandas styling working.

Thanks!

question from:https://stackoverflow.com/questions/65878748/how-to-resolve-this-error-when-trying-to-use-pandas-styling

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The correct way to do this is by:

from pandas.io.formats import style

This is because style is a module of pandas.io.formats package and the correct syntax is:

from package import module

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...