python pandas complex number

后端 未结 4 1110
挽巷
挽巷 2020-12-12 02:54

I am using pandas which very efficiently sorts/filters the data they way I need.

This code worked fine, until I changed the last column to a complex number; now I ge

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-12 03:06

    Or you can parse it directly as a complex number by passing in a converter for that column when you read in the data:

    pd.read_csv('final.dat', header=None,
                names=['X.1', 'X.2', 'X.3', 'X.4','X.5', 'X.6', 'X.7', 'X.8'],
                converters={'X.8': lambda s: np.complex(s.replace('i', 'j'))})
    

提交回复
热议问题