gpt4 book ai didi

python - 如何在 python 3 中将复杂的数据帧值转换为 float ?

转载 作者:太空宇宙 更新时间:2023-11-03 14:40:04 24 4
gpt4 key购买 nike

我使用傅立叶变换将数据帧从时域转换为频域,从而产生虚数/复数值。我需要将 DataFrame 转换为 float 以便能够对数据进行分类。我该如何转换它?

最佳答案

df = pd.DataFrame([complex(x,y) for x,y in 
zip(np.random.randn(3),np.random.randn(3))])
print(df)

Out:
0
0 (0.815555184453+0.942659258939j)
1 (0.725136694628+0.999826686401j)
2 (0.311981899931+0.309615235755j)

如果您想要复数的大小,可以取模(极坐标中的 r):

df.applymap(np.absolute)

Out:
0
0 1.246490
1 1.235102
2 0.439539

如果你想失去虚部,你可以转换为 float :

df.astype(np.float64)

Out:
0
0 0.815555
1 0.725137
2 0.311982

关于python - 如何在 python 3 中将复杂的数据帧值转换为 float ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46612485/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com