Python -- Pandas can't find file but numpy can

Viewed 69

I am at a complete loss here. I am trying to open a txt file in pandas, I have tried multiple different approaches, but I receive the same error message every time. 'no such file'...

What is strange is that this...

import numpy as np
import matplotlib.pyplot as plt
from   matplotlib.ticker import PercentFormatter

full_file = np.loadtxt('2_Feature_Test.txt', delimiter=',')

...works completely fine, however this...

import pandas as pd
import matplotlib.pyplot as plt
from   matplotlib.ticker import PercentFormatter

full_file = pd.read_csv('2_Feature_Test.txt', sep=',')

...does not.

Doesn't matter full path, doesn't matter backslashes or forward slashes or prefixing with r for raw string. Is the problem something to do with pandas and numpy being in different locations? I have no clue. Please, if you have any ideas I am all ears and would love nothing more than to get to the bottom of this. Thanks everyone.

If it helps, this is the full error message I receive...

Traceback (most recent call last):
  File "C:\Users\Pat Oaks\Documents\txt_files\Thonny\lib\site-packages\thonny\workbench.py", line 1449, in event_generate
    handler(event)
  File "C:\Users\Pat Oaks\Documents\txt_files\Thonny\lib\site-packages\thonny\assistance.py", line 138, in handle_toplevel_response
    self._explain_exception(msg["user_exception"])
  File "C:\Users\Pat Oaks\Documents\txt_files\Thonny\lib\site-packages\thonny\assistance.py", line 178, in _explain_exception
    + _error_helper_classes["*"]
  File "C:\Users\Pat Oaks\Documents\txt_files\Thonny\lib\site-packages\thonny\assistance.py", line 176, in <listcomp>
    for helper_class in (
  File "C:\Users\Pat Oaks\Documents\txt_files\Thonny\lib\site-packages\thonny\plugins\stdlib_error_helpers.py", line 555, in __init__
    super().__init__(error_info)
  File "C:\Users\Pat Oaks\Documents\txt_files\Thonny\lib\site-packages\thonny\assistance.py", line 478, in __init__
    self.last_frame_module_source = read_source(self.last_frame.filename)
  File "C:\Users\Pat Oaks\Documents\txt_files\Thonny\lib\site-packages\thonny\common.py", line 252, in read_source
    with tokenize.open(filename) as fp:
  File "C:\Users\Pat Oaks\Documents\txt_files\Thonny\lib\tokenize.py", line 447, in open
    buffer = _builtin_open(filename, 'rb')
FileNotFoundError: [Errno 2] No such file or directory: 'pandas\\_libs\\index.pyx'

UPDATE: due to a more patient man than I actually reading the error message, I realize the issue is most likely with the pandas installation. Install of pandas via conda install pandas failed saying 'the specified procedure could not be found'. Might this have something to do with the issue? Anybody seen this before?

1 Answers

As the comments have said, clearly the missing file is one of pandas', not the file you are trying to read.

Try forcing the reinstall of pandas

pip install -I pandas

or, if using Anaconda

conda install pandas --force-reinstall
Related