I am learning pandas in Python.Below is my code in Terimal:
import pandas as pd
dates = pd.date_range('20130101', periods=6)
Then I get this message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'date_range'
How to solve this problem?
You can't find date_range because you're using pandas version 0.7.0, which is very old (~9 Feb 2012) in pandas time-- the current stable version (29 Jan 2015) is 0.15.2.
You're going to want to upgrade, not only because of bug fixes and new features, but because many of the examples you're going to find on the web won't work for you otherwise.
Related
I am trying to learn panda and tensorflow in colab, but i am having issues importing and manipulating CSV.
When i try to use a .csv file as dataframe in colab i get an error
import io
df = pd.read_csv(io.StringIO(uploaded['GHI training.csv'].decode('utf-8')))
df
Outputs
TypeError Traceback (most recent call last)
<ipython-input-63-d3546ec3306f> in <module>()
2 import io
3
----> 4 df = pd.read_csv(io.StringIO(uploaded['GHI training.csv'][:200].decode('utf-8')))
5 df
TypeError: 'str' object is not callable
here is the notebook i am trying to work
https://colab.research.google.com/drive/14oSPEy8e9FwpiGeFfUpY83UaWKewE_iX
Currently i get TypeError: 'str' object is not callable
i wish to have this CSV as a dataframe
I am not 100% sure why,
but i used created a data_pathfile with the pathfile for the document and it worked
data_pathfile = '../content/GHI training.csv'
df = pd.read_csv(io.StringIO(uploaded[data_pathfile].decode('utf-8')))
I imported a CSV to pandas. However, when I try to use various model packages the cannot coerce one of the columns to float. When I try to do it manually I cannot coerce it either. When I try to check the types of all of my columns, I get the error message below. Any idea whats going on?
values = pd.read_csv(".../train_values.csv")
values.dtypes()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'Series' object is not callable
dtypes is an attribute of the pd.Series not a function. You can access the type by running
values.dtypes
Just starting Computational Investing by Tucker Balch. I'm using virtualbox and installed Ubuntu. After installing QSTK, I ran python Validation.py (Step 7). I keep getting an:
AttributeError: 'module' object has no attribute 'TimeSeries'
There are many similar questions so I believe problem is the use of the same name as the file somewhere in the code. I was wondering if anyone had a solution specific to this class and QSTK.
The full error is:
Traceback (most recent call last):
File "Validation.py", line 122 in <module>
import QSTK.qstkutil.tsutil as tsu
File "usr/local/lib/python2.7/dist-packages/QSTK-0.2.8 py2.7.egg/QSTK/qstkutil/tsutil.py", line 19, in <module>
from QSTK.qstkutil import qsdateutil
File "usr/local/lib/python2.7/dist-packages/QSTK-0.2.8-py2.7.egg/QSTK/qstkutil/qsdateutil.py", line 38, in <module>
GTS_DATES = _cache_dates()
File "usr/local/lib/python2.7/dist-packages/QSTK-0.2.8-py2.7.egg/QSTK/qstkutil/qsdateutil.py", line 36, in _cache_dates
return pd.TimeSeries(index=dates, data=dates)
AttributeError: 'module' object has no attribute 'TimeSeries'
I encountered this issue too. This caused by the pandas lib. You can get into the path(my file path is /Library/Python/2.7/site-packages/QSTK/qstkutil) where the qstkutil.py of QSTK located. Then change all the 'TimeSeries' of this file as 'Series'.
You can also get some insights from here(https://github.com/QuantSoftware/QuantSoftwareToolkit/issues/73)
Corley is spot on. You can solve the problem by changing 2 occurrences of "TimeSeries" to "Series" in /usr/local/lib/python2.7/dist-packages/QSTK-0.2.8-py2.7.egg/QSTK/qstkutil/qsdateutil.py. "TimeSeries" also appears once in /usr/local/lib/python2.7/dist-packages/QSTK-0.2.8-py2.7.egg/QSTK/qstkutil/tsutil.py but I haven't encountered an error yet due to it.
Changing TimeSeries to Series corrects the issue for me.
Seems that
import pandas as pd;
pd.TimeSeries = pd.Series
should work, but did not for me.
I am already using an xlrd package. The code I am working on always returns an error message:
Traceback (most recent call last):
File "diffoct8.py", line 17, in <module>
row = rs.get(row_number)
AttributeError: 'Sheet' object has no attribute 'get'
What could be the problem?
Is there a newer version of XLRD?. If yes, how can I install it in Ubuntu?
Here you can get latest xlrd package. https://pypi.python.org/pypi/xlrd
From my understanding, you just want to get information from a row in a sheet. I assume there are 10 elements in a row.
Try this:
...
element_num = 10
row = []
for i in xrange(element_num):
row.append(rs.cell(row_number, i).value)
...
The method get() does not exist (It was purely used to show the approach you should take and where the problem was in your previous question). I've update my answer to that question to show you how you should use the row() method, as instructed in the documentation.
How to convert from Python date to Excel date using xlrd module? How to convert a python datetime.datetime to excel serial date number suggests a 'manual' solution, I wonder if it is the best way.
Xlrd document suggests to use xlrd.xldate_from_date_tuple
but
>>> import xlrd
>>> xlrd.xldate_from_date_tuple
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'xldate_from_date_tuple'
Could you help? Thanks.
Use xlrd.xldate.xldate_from_date_tuple