import pandas as pd
import pandas.io.data as web # as we have to use only pandas function
#Second, retrieve the data from, say, Google itself:
stock = web.DataReader('IBM',data_source='yahoo',start='01/01/2011', end='01/01/2013')
# end of question 1
print type(stock) # Class Type is pandas.core.frame.DataFrame
IBM_dataframe = pd.DataFrame(stock)
Traceback (most recent call last):
File "", line 2, in
import pandas.io.data as web # as we have to use only pandas function
File "C:\Anaconda2\lib\site-packages\pandas\io\data.py", line 2, in
"The pandas.io.data module is moved to a separate package "
ImportError: The pandas.io.data module is moved to a separate package (pandas-datareader). After installing the pandas-datareader package (https://github.com/pydata/pandas-datareader), you can change the import from pandas.io import data, wb to from pandas_datareader import data, wb.
import pandas_datareader as web
stock = web.DataReader('IBM',data_source='yahoo',start='01/01/2011', end='01/01/2013')
Traceback (most recent call last):
File "", line 1, in
stock = web.DataReader('IBM',data_source='yahoo',start='01/01/2011', end='01/01/2013')
AttributeError: 'module' object has no attribute 'DataReader'
change the import pandas.io.data as web to import pandas_datareader as web but now not able to get data plz suggest getting error
'module' object has no attribute 'DataReader'
Use the following:
from pandas_datareader import data, wb
DAX = data.DataReader(name='^GDAXI', data_source='yahoo',start='2000-1-1')
Related
My code is:
from __future__ import division
from pyomo.environ import *
import openpyxl
import xlrd
import pyutillib
import win32com
model = AbstractModel()
data = DataPortal()
model.A = Set(dimen=2)
model.p = Param(model.A)
data.load(filename='excel.xls', range='PPtable', param=model.p, index=model.A)
instance = model.create_instance(data)
The error I get:
runfile('C:/Users/faube/.spyder-py3/Pyomo Excel test.py', > > >wdir='C:/Users/faube/.spyder-py3')
Traceback (most recent call last):
File ~.spyder-py3\Pyomo Excel test.py:20 in
data.load(filename='excel.xls', range='PPtable',
File ~\Anaconda3\envs\LTSP\lib\site->packages\pyomo\dataportal\DataPortal.py:146 in load
self.connect(**kwds)
File ~\Anaconda3\envs\LTSP\lib\site-> packages\pyomo\dataportal\DataPortal.py:107 in connect
raise IOError("Unknown file format '%s'" % tmp)
OSError: Unknown file format 'xls'
Any idea? Thanks!
Here is my my code
import theano
import numpy
import os
from keras.models import Sequential
model2 = Sequential()
model2.load_weights("/home/console/Desktop/Apu_code/_epoch_0_e199-0.04.hdf5")
'''model = loaded_models('.)'''
print('loaded')
and getting error :
Using Theano backend.
Traceback (most recent call last):
File "try.py", line 7, in <module>
model2.load_weights("/home/console/Desktop/Apu_code/_epoch_0_e199-0.04.hdf5")
File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 2369, in load_weights
str(len(flattened_layers)) + ' layers.')
Exception: You are trying to load a weight file containing 12 layers into a model with 0 layers.
I just do
model0 = keras.models.load_model(hdf5Fname)
to load the file into the variable model0 in order to do sth like
prediction0 = model0.predict( image)[0][0]
and so on...
I get an errr when using scipy.stats. in a script after importing scipy.
AttributeError: 'module' object has no attribute 'stats'
Within script editor I can click on stats after typing scipy. from the pulldown menu,
within python console I can not select python.stats from the pulldown menu, it's not there.
I'm using pandas 2.7 and SciPy 0.13.0
Why is that?
Any known issues?
expanding on my comment (to have a listed answer).
Scipy, as many other large packages, doesn't import all modules automatically. If we want to use the subpackages of scipy, then we need to import them directly.
However, some scipy subpackages load other scipy subpackages, so for example importing scipy.stats also imports a large number of the other packages. But I never rely on this to have the subpackage available in the namespace.
In many packages that use scipy, the preferred pattern is to import the subpackages to have them available by their names, for example:
>>> from scipy import stats, optimize, interpolate
>>> import scipy
>>> scipy.stats
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'stats'
>>> scipy.optimize
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'optimize'
>>> import scipy.stats
>>> scipy.optimize
<module 'scipy.optimize' from 'C:\Python26\lib\site-packages\scipy\optimize\__init__.pyc'>
This is expected. Most of the subpackages are not imported when you just do import scipy. There are a lot of them, with a lot of heavy extension modules that take time to load. You should always explicitly import the subpackages that you want to use.
https://github.com/scipy/scipy/issues/13618
if you import scipy alone like this:
import scipy
then you use:
scipy.stats
You will get:
AttributeError: module 'scipy' has no attribute 'stats'
You have to import like this:
import scipy.stats
or
import scipy
import stats
I have a manager in my django project and am implementing a filter as below.
I start the django shell and get this error:
>>> from django.http import HttpRequest
>>> r=HttpRequest()
>>> r.session=()
>>> from movierating.models import *
>>> RatingModel.statManager.RatingTimeLine(r)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/data/dashapp/movierating/managers.py", line 27, in RatingTimeLine
(data,display,err)=self.getdatacache(request)
File "/data/dashapp/movierating/managers.py", line 11, in getdatacache
filterDict=request.session.get('RatingFilter',{})
AttributeError: 'tuple' object has no attribute 'get'
>>> from django.http import HttpRequest
>>> r=HttpRequest()
>>> r.session()
Traceback (most recent call last):
File "<console>", line 1, in <module>
AttributeError: 'HttpRequest' object has no attribute 'session'r code here
The file manager.py looks like this:
import json,datetime
from django.db import models
from django.db.models import *
from pandas import *
from urllib import urlencode
import hashlib
from django.core.cache import cache
from web.extras import *
class RatingManager(models.Manager):
def getdatacache(self,request):
filterDict=request.session.get('RatingFilter',{})
(fapply,display,err)=normalizeFilter(self.model,filterDict)
cache_id=urlencode(fapply.items())
cache_id=hashlib.md5('RatingFilter'+cache_id).hexdigest()
data=None
if data==None:
res=self.model.objects.order_by('date').filter(**fapply).values('date').annotate(
RatingCounts = Count('rating'),
RatingSum = Sum('rating'),
)
data=DataFrame(list(res))
data['AverageRating']=data['RatingSum']/data['RatingCounts']
cache.set(cache_id,data)
return (data,display,err)
def RatingTimeLine(self,request):
jsondata={}
jsondata['chartconfig']={}
jsondata['chartconfig']['title']="Average Movie Rating per Day"
jsondata['chartconfig']['names']=['AverageRating']
(data,display,err)=self.getdatacache(request)
jsondata['chartconfig']['errors']="<br/>".join(err)
jsondata['chartconfig']['subtitle']="<br/>".join(display)
jsondata['series']=data[['data','AverageRating']].values.tolist()
data=json.dumps(jsondata,cls = SeriesEncoder)
return {'data':data}
I have this model in my models.py:
class RatingModel(models.Model):
movie=models.ForeignKey(MovieModel)
user=models.ForeignKey(userModel)
rating=models.IntegerField()
date=models.DateField()
objects=models.Manager() #default manager
statManager=RatingManager() #new manager class
# FilterMapping={
#'movie':'movie__name', #django relational
# }
def __unicode__(self):
return "id: %d rating for movie is %s" %(self.id,self.movie.name) #relationships
class Meta:
app_label = 'movierating'
db_table = 'rating'
What could be the possible error in this line?
filterDict=request.session.get('RatingFilter',{})
In your third line you say r.session=() - that is, you're assigning an empty tuple to r.session. Your code later tries to call get() on this tuple, which isn't a supported operation.
I'm not sure what you're trying to do here. request.session is normally filled in by the session middleware. If you're trying to test your code programmatically, you might want to look into the Django testing framework, which supports sessions.
I want to setup a Cron job to run a django file.
What I want to know is django-cron a good option for this? i.e. or are there any other apps that can be used?
If no, how to run a django file through command line ?
admin#ADMIN-PC ~/workspace/bolt (master)
$ python ./log/cron.py
Traceback (most recent call last):
File "./log/cron.py", line 3, in <module>
from account.models import UserProfile
ImportError: No module named account.models
I have set the following variable
admin#ADMIN-PC ~/workspace/bolt (master)
$ export DJANGO_SETTINGS_MODULE=settings
I keep getting these errors as the files that are being referenced have direct imports
from foo.models import *
Any help will be highly appreciated.
Custom Command
from django.core.management.base import BaseCommand, CommandError
import pdb
import datetime
from too.models import UserProfile
from foo.api import end_all_foo_conversations
class Command(BaseCommand):
# in minutes
def handle(self,*args,**options):
print datetime
The error I am getting while trying to run the command is as follows:-
'queryset': self.rel.to._default_manager.using(db).complex_fi
imit_choices_to),
AttributeError: 'str' object has no attribute '_default_manager'
I think you should write a custom management command and run it through manage.py.