0
votes

I'm trying to read from a CSV file using the pandas library in python (using spyder (Python 3.7)), But I am getting an error

Traceback (most recent call last):

File "<ipython-input-104-744f03c12bee>", line 1, in datasets = pd.read_csv('Data.csv')

File "\Continuum\anaconda3\lib\site-packages\pandas\io\parsers.py", line 702, in parser_f return _read(filepath_or_buffer, kwds)

File "\Continuum\anaconda3\lib\site-packages\pandas\io\parsers.py", line 435, in _read data = parser.read(nrows)

File "\Continuum\anaconda3\lib\site-packages\pandas\io\parsers.py", line 1154, in read df = DataFrame(col_dict, columns=columns, index=index)

File "\Continuum\anaconda3\lib\site-packages\pandas\core\frame.py", line 392, in init mgr = init_dict(data, index, columns, dtype=dtype)

File "\Continuum\anaconda3\lib\site-packages\pandas\core\internals\construction.py", line 212, in init_dict return arrays_to_mgr(arrays, data_names, index, columns, dtype=dtype)

File "\Continuum\anaconda3\lib\site-packages\pandas\core\internals\construction.py", line 56, in arrays_to_mgr arrays = _homogenize(arrays, index, dtype)

File "\Continuum\anaconda3\lib\site-packages\pandas\core\internals\construction.py", line 277, in _homogenize raise_cast_failure=False)

File "\Continuum\anaconda3\lib\site-packages\pandas\core\internals\construction.py", line 582, in sanitize_array subarr = _try_cast(data, True, dtype, copy, raise_cast_failure)

File "\Continuum\anaconda3\lib\site-packages\pandas\core\internals\construction.py", line 720, in _try_cast subarr = np.array(arr, dtype=object, copy=copy)

TypeError: 'numpy.ndarray' object is not callable

I have imported the numpy library as np, as well as the pandas library as pd; the working directory has been set correctly to the same as the file save location.

import pandas as pd
datasets = pd.read_csv('Data.csv')

Following is the data that I am currently working on: Data

1
can you provide bits of your csv ? Did you try this exact code without anything else and it still fails ? I not, we need more information.Derlin
your csv seems to be tab or space delimited, try using the sep parameter, e.g.: pd.read_csv('Data.csv', sep=' ')Derlin
The call looks right - for common csv files and pandas setup. So what's different in your case? A sample of the file might help. Traceback of the error might help. If you want help you need to provide more information. Otherwise we'll be guessing.hpaulj
Whenever you report a Python error, include the complete traceback (i.e. the complete error message) in the question. There is useful information in there.Warren Weckesser
@Derlin, I have added the data in the question, I tried using other CSV files as well was make a new CSV file. Both times I got the same error. One file having 1 row was read sucessfully, others failed. I also tried using the sep parameter, it stil gave me the same error. Thank you!Tanuj Udani

1 Answers

0
votes

Actually your file(data.csv) is not a csv file. Its in PNG format. So, you can use PIL module in python.

from PIL import Image

imframe = Image.open('data.csv')
imframe