import numpy as np
a=np.load('ampli/array.npy')
print(a)
Im trying to print an npy array like this from colab. I've used this exact syntax to print other arrays and it has worked but this isnt working suddenly. I tried opening a new notebook and uploaded the npy file there and it printed it out without any issue. How can I resolve this issue?
The error suggests that it is your print that is not callable.
Where the line print(a) fails, replace by print("1") and make sure it fails also.
Then find where the print built-in method is being assigned to some tuple.
I am using "dde" package in Python and my Excel input is
=XXExcecute|'some_code_for_financial_products'!'field_name'
As you can see it has parenthesis around strings.
However, the problem is that I don't know how to "translate" the input to
dde module's function inputs.
I know that inside "Create", I should type in the "XXExecute" part but
don't know what to pass in ConnectTo, given the Excel input is what I mentioned above.
and this function is where my code failed, giving me this messages:
c.ConnectTo("'P10102'","'9001'")
dde.error: ConnectTo failed
the entire code is as follows:
import win32ui
import dde
import pandas as pd
#making an instance
server = dde.CreateServer()
#executing instance
server.Create("XXExecute")
#DDEconversation
c= dde.CreateConversation(server)
c.ConnectTo('X10102','')
#or I tried to pass in ('X10102','9001') but it failed as well.
c.Connected()
c.Request("9001")
I'm using Comtypes in Python. I'm newbe in Python.
The COM object I'am using in Comtypes in Python works well in Excel VBA.
The syntaxes of the COM object that I try to use in Python work like this in VBA:
object.mymethode1(vba_array_of_defined_size) 'it takes as argument of an array of defined size then does something else
object.mymethode2(vba_array_of_defined_size) 'it takes as argument of an array of defined size then change directly the value of this array
I try to use the same syntaxe in Python with Comtypes, but none of the two methodes works
Below the error message:
COMError: (-2147221503, 'Invalid advise flags', ('Invalid sized array passed to mymethode', 'com_object_name', None, 1000440, None))
Anyone has any idea ? Thanks a lot !
So I am trying to run a code that was regularly working, but now I get an error
The first lines of my code are:
import numpy as np
array = np.array([0,1,2])
Then, I get the following error:
'list' object is not callable
This code is working fine in Jupyter notebook. You might want to restart your session and try again. An other alternative would be to use a different name to assign the array object instead of 'array' itself.
I'm not looking for a solution here as I found a workaround; mostly I'd just like to understand why my original approach didn't work given that the work around did.
I have a dataframe of 2803 rows with the default numeric key. I want to replace that with the values in column 0, namely TKR.
So I use f.set_index('TKR') and get
f.set_index('TKR')
Traceback (most recent call last):
File "<ipython-input-4-39232ca70c3d>", line 1, in <module>
f.set_index('TKR')
TypeError: 'str' object is not callable
So I think maybe there's some noise in my TKR column and rather than scrolling through 2803 rows I try f.head().set_index('TKR')
When that works I try f.head(100).set_index('TKR') which also works. I continue with parameters of 500, 1000, and 1500 all of which work. So do 2800, 2801, 2802 and 2803. Finally I settle on
f.head(len(f)).set_index('TKR')
which works and will handle a different size dataframe next month. I would just like to understand why this works and the original, simpler, and (I thought) by the book method doesn't.
I'm using Python 3.6 (64 bit) and Pandas 0.18.1 on a Windows 10 machine
You might have accidentally assigned the pd.DataFrame.set_index() to a value.
example of this mistake: f.set_index = 'intended_col_name'
As a result for the rest of your code .set_index was changed into a str, which is not callable, resulting in this error.
Try restarting your notebook, remove the wrong code and replace it with f.set_index('TKR')
I know it's been a long while, but I think some people may need the answer in the future.
What you do with f.set_index('TKR') is totally right as long as 'TKR' is a column of DataFrame f.
That is to say, this is a bug you are not supposed to have. It is always because that you redefine some build-in function methods or functions of python in your former steps(Possibly 'set_index'). So, the way to fix is to review your code to find out which part is wrong.
If you are using Jupiter notebook, restart it and run this block only can fix this problem.
I believe I have a solution for you.
I ran into the same problem and I was constructing my dataframes from a dictionary, like this:
df_beta = df['Beta']
df_returns = df['Returns']
then, trying to do df_beta.set_index(Date) would fail. My workaround was
df_beta = df['Beta'].copy()
df_returns = df['Returns'].copy()
So apparently, if you build your dataframes as a "view" of another existing dataframe, you can't set index and it will raise 'Series not callable' error. If instead you create an explicit new object copying the original dataframes, then you can call reset_index, which is what you kind of do when you compute the head.
Hope this helps, 2 years later :)
I have the same problem here.
import tushare as ts
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
ts.set_token('*************************************')
tspro = ts.pro_api()
gjyx = tspro.daily(ts_code='000516.SZ', start_date='20190101')
# this doesn't work
# out:'str' object is not callable
gjyx = gjyx.set_index('trade_date')
# this works
gjyx = gjyx.head(len(gjyx)).set_index('trade_date')
jupyter notebook 6.1.6, python 3.9.1, miniconda3, win10
But when I upload this ipynb to ubuntu on AWS, it works.
I once had this same issue.
This simple line of code keep throwing TypeError: 'series' object is not callable error again and again.
df = df.set_index('Date')
I had to shutdown my kernel and restart the jupyter notebook to fix it.