在python 3.7中导入熊猫时出错

时间:2019-01-21 09:10:54

标签: python python-3.x

导入熊猫时出现错误

Traceback (most recent call last):
  File "C:/Users/kj/PycharmProjects/kj/parsing.py", line 5, in <module>
    import pandas
  File "H:\Python\New\lib\pandas\__init__.py", line 23, in <module>
    from pandas.compat.numpy import *
  File "H:\Python\New\lib\pandas\compat\__init__.py", line 421, in <module>
    if LooseVersion(dateutil.__version__) < LooseVersion('2.5'):
  File "C:\Program Files\Python\Python37\Lib\distutils\version.py", line 52, in __lt__
    c = self._cmp(other)
  File "C:\Program Files\Python\Python37\Lib\distutils\version.py", line 337, in _cmp
    if self.version < other.version:
TypeError: '<' not supported between instances of 'str' and 'int'

import pandas
df = pandas.read_excel(open('Test.csv','rb'), sheetname='Sheet 1')
grouped = df.groupby('Date (IT)')

2 个答案:

答案 0 :(得分:1)

看起来您的Date (IT)列包含混合值(字符串和整数,日期或缺失值)。因此,当熊猫尝试比较每个值时,它会因为类型不同而失败。请查看列数据,并确保所有数据均采用有效格式。

答案 1 :(得分:0)

我目前尚未安装PyCharm,但可以在命令行中尝试运行:

pip uninstall pandas 

随后是重新安装:pip install pandas

或者您始终可以尝试从PyCharm运行它。它将自动建议安装缺少的软件包。