[Python] Python TypeError: expected string or buffer using Pandas

Discussão em 'Python' iniciado por Stack, Março 12, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to run a Python script to extract certain column from an Excel file.

    I found Pandas might be a good solution, so I tried with following code:

    import pandas

    for filename in InFileslist:
    fields = ['MRN']
    df = pandas.read_excel(filename, skipinitialspace=True, usecols=fields)
    print df.keys()
    print df.MRN


    And below is the error message that I got.

    Traceback (most recent call last):
    File "/home/FetchingData_v3.py", line 10, in <module>
    import pandas
    File "/usr/local/lib/python2.7/dist-packages/pandas/__init__.py", line 45, in <module>
    from pandas.io.api import *
    File "/usr/local/lib/python2.7/dist-packages/pandas/io/api.py", line 15, in <module>
    from pandas.io.gbq import read_gbq
    File "/usr/local/lib/python2.7/dist-packages/pandas/io/gbq.py", line 52, in <module>
    if LooseVersion(_GOOGLE_FLAGS_VERSION >= '2.0.0'):
    File "/usr/lib/python2.7/distutils/version.py", line 265, in __init__
    self.parse(vstring)
    File "/usr/lib/python2.7/distutils/version.py", line 274, in parse
    self.component_re.split(vstring))
    TypeError: expected string or buffer


    I am not sure whether this is something to do with Pandas installation issue or code issue.

    Continue reading...

Compartilhe esta Página