小编Joh*_*rer的帖子

Python 数据框:将负极角更改为正极角

这不起作用:

df[df['angle'] < 0]] += 360
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?我需要一个已经存在的熊猫数据框,其中负角和正角更新为正极坐标角(0 到 360 度)。

有:

[-135, -90, -45, 180, 135, 90, 45, 0, etc... ] # polar 'angles' in degrees (with negatives)
Run Code Online (Sandbox Code Playgroud)

想:

[315, 270, 225, 180, 135, 90, 45, 0, etc... ] # polar 'angles' in degrees (positive only)
Run Code Online (Sandbox Code Playgroud)

// 编辑(响应)://////////////////////////////////////// ///////////////////////////////////////////////// ///////////////////////////////

这一行df[df['angle'] < 0]] += 360给出了一个类型错误:
“类型错误:无法操作 360,块值必须是 str,而不是浮点数。”

数据框'angle'的信息为:
“名称:角度,dtype:in64,

我使用的原始“蛮力”解决方案是:

for i in range(len(df['angle'])):
    if df['angle'][i] < 0:
        df['angle'][i] += 360
Run Code Online (Sandbox Code Playgroud)

这有效,但速度很慢,并给出警告,然后告诉我查找有关数据帧索引的文档。

python-3.x pandas polar-coordinates

4
推荐指数
1
解决办法
2254
查看次数

标签 统计

pandas ×1

polar-coordinates ×1

python-3.x ×1