How can I read a file with complex number and convert to numpy array as complex datatype?

300 views Asked by At

I have a .excel file with complex number data and want it to convert to complex numpy array.

enter image description here

I tried the following code:

df=pd.read_excel(location, sheet_name='complex')

np_complex=df.to_numpy(dtype=complex)

It has worked previously, although nothing is changed (I think) but now it is raising the error

TypeError: must be real number, not str 

In line np_complex=df.to_numpy(dtype=complex)

Can anyone suggest the change in code?

1

There are 1 answers

0
Shubham luharuka On

Your code is right. Try to rebuild then run. When I run this code it works fine my IDE. This is code Code and its result Result.