0

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?

7
  • We need more information. Where did the error occur? What was different previously vs now? Commented Jun 1, 2021 at 2:46
  • @hpaulj Error occured in the line "np_complex=df.to_numpy(dtype=complex)", although I do not think any thing has been changed in the excel file and code too. Commented Jun 1, 2021 at 2:56
  • have a look at df.dtypes to make sure the data types are correct Commented Jun 1, 2021 at 3:17
  • @JanWilamowski all datatypes are object in the excel file. Commented Jun 1, 2021 at 3:20
  • Could you show part of df.to_numpy()? This should give a clearer idea of what it's trying to convert to complex. In my tests "1+3j" and "(1+3j)"` both work. Commented Jun 1, 2021 at 3:29

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.