Python Pandas 'str' object is not callable -


i new python , trying pandas library. here code read csv file without headers:

import pandas pnd import numpy np import matplotlib.pyplot plt import matplotlib mpl  pnd.set_option('max_columns', 50) mpl.rcparams['lines.linewidth'] = 2  headers = ['orderid', 'orderdate', 'userid', 'totalcharges'] dtypes = {'orderid': 'int', 'orderdate': 'str', 'userid': 'int', 'totalcharges':'float'} parse_dates = ['orderdate'] df = pnd.read_csv('raw_flight_data.csv', sep='\t', header=none,                   names=headers,converters=dtypes,parse_dates=parse_dates) 

this code gives me error :-

runfile('c:/users/rohan.arora/desktop/python/example.py', wdir='c:/users/rohan.arora/desktop/python') traceback (most recent call last):    file "<ipython-input-47-43fc22883149>", line 1, in <module>     runfile('c:/users/rohan.arora/desktop/python/example.py', wdir='c:/users/rohan.arora/desktop/python')    file "c:\users\rohan.arora\anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile     execfile(filename, namespace)    file "c:\users\rohan.arora\anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 87, in execfile     exec(compile(scripttext, filename, 'exec'), glob, loc)    file "c:/users/rohan.arora/desktop/python/example.py", line 13, in <module>     names=headers,converters=dtypes,parse_dates=parse_dates)    file "c:\users\rohan.arora\anaconda2\lib\site-packages\pandas\io\parsers.py", line 646, in parser_f     return _read(filepath_or_buffer, kwds)    file "c:\users\rohan.arora\anaconda2\lib\site-packages\pandas\io\parsers.py", line 401, in _read     data = parser.read()    file "c:\users\rohan.arora\anaconda2\lib\site-packages\pandas\io\parsers.py", line 939, in read     ret = self._engine.read(nrows)    file "c:\users\rohan.arora\anaconda2\lib\site-packages\pandas\io\parsers.py", line 1508, in read     data = self._reader.read(nrows)    file "pandas\parser.pyx", line 848, in pandas.parser.textreader.read (pandas\parser.c:10415)    file "pandas\parser.pyx", line 870, in pandas.parser.textreader._read_low_memory (pandas\parser.c:10691)    file "pandas\parser.pyx", line 947, in pandas.parser.textreader._read_rows (pandas\parser.c:11728)    file "pandas\parser.pyx", line 1044, in pandas.parser.textreader._convert_column_data (pandas\parser.c:13129)    file "pandas\parser.pyx", line 2115, in pandas.parser._apply_converter (pandas\parser.c:28771)  typeerror: 'str' object not callable 

i using anaconda spyder 3.1.2 , running python 2.7.13.

i think need remove ' types, not string representation of types:

dtypes = {'orderid': 'int', 'orderdate': 'str', 'userid': 'int', 'totalcharges':'float'} 

to:

dtypes = {'orderid': int, 'orderdate': str, 'userid': int, 'totalcharges': float} 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -