Im having issues understand what arguments to send to the growattServer 1.4.0 function api.dashboard_data()
The function looks like
def dashboard_data(self, plant_id, timespan=Timespan.hour, date=None):
class Timespan(IntEnum):
hour = 0
day = 1
month = 2
If I try
print(api.dashboard_data('INVERTERID',timespan=0,date='2023-02-01'))
I get:
TypeError: unsupported operand type(s) for 'in': 'int' and 'EnumType'
I get the same error if I do
print(api.dashboard_data('INVERTERID',0,date='2023-02-01'))
I do not understand what arguments to pass for the timespan function and would appricate some help with this.
For timespan you are passing in a 0 -- in both attempts; includeing the parameter name makes no difference.
Try:
print(api.dashboard_data('INVERTERID', Timespan.hour, date='2023-02-01')
Questions for you:
can plant_id be a string?
can date be a string? Or should it be a datetime.date?
Related
So, I'm building a model and trying to use | for a new column and I'm confused as to what I'm doing wrong. It's supposed to make a new column and type 1 when the value is true.
For example, this worked :
feature_matrix["After 2016"] = (feature_matrix.index.year > 2016).astype(int)
However this does nothing :
feature_matrix["Summer"] = (feature_matrix.index.month == 6|7|8|9).astype(int)
Same thing goes for this when I try to do the weekend using the same method.
I tried solving it using :
feature_matrix["Summer"] = (feature_matrix.index.month == 6| feature_matrix.index.month == 7).astype(int)
But that gives me : unsupported operand type(s) for |: 'int' and 'Int64Index'
We have isin
(feature_matrix.index.month.isin([6,7,8,9]))
Yoben's answer is correct and complete, but a note: 6|7|8\9 is always true, and unless you have True in your column, this will do nothing.
def function1(self,*windows):
xxx_per_win = [[] for _ in windows]
for i in range(max(windows),self.file.shape[0]):
for j in range(len(windows)):
zz = self.file['temp'][i-windows[j]:i].quantile(0.25)
...
...
...
o = classX(file)
windows = [3,10,20,40,80]
output = o.function1(windows)
If I run the code above it says:
for i in range(max(windows),self.file.shape[0]):
TypeError: 'list' object cannot be interpreted as an integer
and:
zz = self.file['temp'][i-windows[j]:i].quantile(0.25)
TypeError: unsupported operand type(s) for -: 'int' and 'list'
This problem only occurs when windows is variable length (ie *windows and not just windows).
How do I fix this? What is causing this?
The max function expects to be passed multiple arguments, not a tuple containing multiple arguments. Your windows variable is a tuple.
So, not:
for i in range(max(windows),self.file.shape[0]):
Do this instead:
for i in range(max(*windows),self.file.shape[0]):
On your second error, involving the line:
zz = self.file['temp'][i-windows[j]:i].quantile(0.25)
# TypeError: unsupported operand type(s) for -: 'int' and 'list'
Ok, you are subtracting, and it's complaining that you can't subtract a list from an integer. And since I have no idea what windows[j] contains, I can't say whether there's a list in there or not.. but if there is, there can't be. You haven't given us a working example to try.
What I suggest you do is to put some debugging output in your code, eg:
print('i=%s, j=%s, windows[j]=%s' % (i, j, windows[j]))
and thus see what your data looks like.
I have a class which has the attribute 'latest_level' and this should be a floating point number. I then have a method which includes latest_level in an equation to return another floating point number. In this method, if I use the line:
def relative_water_level(self):
level = float(self.latest_level)
I get the output:
TypeError: float() argument must be a string or a number, not 'list'
Which I assume means self.latest_level is a list. If I change this line to:
def relative_water_level(self):
level = float(self.latest_level[0])
I get the output:
TypeError: 'float' object is not subscriptable
Which I assume means self.latest_level is a float. Anybody have any idea why this is happening and how I can get it to treat self.latest_level as a float?
Edit: I don't try and subscript later. The rest of the method is:
level = float(self.latest_level[0])
low = float(self.typical_range[0])
high = float(self.typical_range[1])
return ((level - low)/high)
And the Error specifies that the Error is in the line mentioned above
File "C:\Users\rache\Documents\Flood Warning\partia-flood-warning
system\floodsystem\station.py", line 58, in relative_water_level
level = float(self.latest_level[0])
TypeError: 'float' object is not subscriptable
subscriptable object refers to something which implements __getitem__() method. you might be changing latest_level's type. I have added a sample code which will produce the same error.
class Level:
latest_level = 20.0
def getLevels(self):
self.latest_level = [20,30]
def relative_water_level(self):
level = float(self.latest_level[0])
print(level)
waterLevel = Level()
waterLevel.relative_water_level()
waterLevel.getLevels()
waterLevel.relative_water_level()
for debugging use type(self.latest_level) before float(self.latest_level) and change according to stack trace.
Problem solved. Turns out some of the flood monitoring stations I'm importing data from are producing messed up data with lists of numbers all over the place, so I've just had to ignore those stations for now. Thanks for all your help and good luck to any of you who live near those rivers!
a'$'
money=1000000;
portfolio=0;
value=0;
value=(yahoostock.get_price('RIL.BO'));
portfolio=(16*(value));
print id(portfolio);
print id(value);
money= (money-portfolio);
'''
I am getting the error:
Traceback (most recent call last):
File "/home/dee/dee.py", line 12, in <module>
money= (value-portfolio);
TypeError: unsupported operand type(s) for -: 'str' and 'str'
Since money is integer and so is portfolio, I cant solve this problem..anyone can help???
value=(yahoostock.get_price('RIL.BO'));
Apparently returns a string not a number. Convert it to a number:
value=int(yahoostock.get_price('RIL.BO'));
Also the signal-to-noise ratio isn't very high. You've lots of (,), and ; you don't need. You assign variable only to replace them on the next line. You can make your code nicer like so:
money = 1000000
value = int(yahoostock.get_price('RIL.BO'));
portfolio = 16 * value;
print id(portfolio);
print id(value);
money -= portfolio;
money and portfolio are apparently strings, so cast them to ints:
money= int( float(money)-float(portfolio) )
As the error message clearly states, both are string, cast with int(var).
Note:
Let's see what can we decude from the error message:
portfolio must be string(str), which means value is also a string. Like this:
>>> 16*"a"
'aaaaaaaaaaaaaaaa'
and apparently you missed to post relevant code because the error message tells you that money is str as well.
I think the problem here is assuming that because you have initialised variables with integer values they will remain as integers. Python doesn't work this way. Assigning a value with = only binds the name to the value without paying any attention to type. For example:
a = 1 # a is an int
a = "Spam!" # a is now a str
I assume yahoostock.getprice(), like many functions that get data from websites, returns a string. You need to convert this using int() before doing your maths.
In python I get this error:
TypeError: 'int' object is unsubscriptable
This happens at the line:
sectorcalc[i][2]= ((today[2]/yesterday[2])-1)
I couldn't find a good definition of unsubscriptable for python anywhere.
for quote in sector[singlestock]:
i+=1
if i < len(sector):
if i==0:
sectorcalc[i][0]= quote[0]
sectorcalc[i][2]= 0
sectorcalc[i][3]= 0
sectorcalc[i][4]= 0
sectorcalc[i][5]= 0
sectorcalc[i][6]= 0
sectorcalc[i][7]= 0
else:
yesterday = sector[singlestock-1][i]
print yesterday
today = quote
print type(today[2])
sectorcalc[i][2]= ((today[2]/yesterday[2])-1)
sectorcalc[i][3]= (today[3]/yesterday[3])-1
sectorcalc[i][4]= (today[4]/yesterday[4])-1
sectorcalc[i][5]= (today[5]/yesterday[5])-1
sectorcalc[i][6]= (today[6]/yesterday[6])-1
sectorcalc[i][7]= (today[7]/yesterday[7])-1
What does this error mean?
The "[2]" in today[2] is called subscript.
This usage is possible only if "today"
is a sequence type. Native sequence
types - List, string, tuple etc
Since you are getting an error - 'int' object is unsubscriptable. It means that "today" is not a sequence but an int type object.
You will need to find / debug why "today" or "yesterday" is an int type object when you are expecting a sequence.
[Edit: to make it clear]
Error can be in
sectorcalc[i]
today (Already proved is a list)
yesterday
This is confusing to read:
today = quote
Is today = datetime.date.today()? Why would a date suddenly refer to a quote? Should the variable name be quoteForToday or something more expressive? Same for yesterday. Dividing two dates as you do makes no sense to me.
Since this is a quote, would today and yesterday refer to prices or rates on different days? Names matter - choose them carefully. You might be the one who has to maintain this six months from now, and you won't remember what they mean, either.
Not that the code you wrote is valid, but I can't see why you wouldn't use a loop.
for j in range(2,7):
sectorcalc[i][j] = (today[j]/yesteday[j])-1
instead of
sectorcalc[i][2]= ((today[2]/yesterday[2])-1)
sectorcalc[i][3]= (today[3]/yesterday[3])-1
sectorcalc[i][4]= (today[4]/yesterday[4])-1
sectorcalc[i][5]= (today[5]/yesterday[5])-1
sectorcalc[i][6]= (today[6]/yesterday[6])-1
sectorcalc[i][7]= (today[7]/yesterday[7])-1
How to reproduce that error:
myint = 57
print myint[0]
The people who wrote the compiler said you can't do that in the following way:
TypeError: 'int' object is unsubscriptable
If you want to subscript something, use an array like this:
myint = [ 57, 25 ]
print myint[0]
Which prints:
57
Solution:
Either promote your int to a list or some other indexed type, or stop subscripting your int.