express plotly - TypeError: unsupported operand type(s) for /: 'str' and 'int'
express plotly - TypeError: unsupported operand type(s) for /: 'str' and 'int'
我正在尝试绘制带有百分比列的数据框,并在图表中快速抛出。
收到
TypeError: unsupported operand type(s) for /: 'str' and 'int'
列:
Meeting_inv pchanges_dax Unscheduled_orde pharmacy_nam dis yyyy/mm
0 1% 17% 5 x r 2011-1
1 2% 11% 1 x r 2011-2
2 5% 10% 7 x r 2011-6
3 10% 10% 5 x r 2011-7
4 2% 5% 14 x r 2011-8
代码:
import plotly.express as px
px.scatter(df3, x="Meeting_inventory_target", y="Unscheduled_orders", animation_frame="yyyy/mm", animation_group="pharmacy_name",
size="pchanges_dax", color="pharmacy_name", hover_name="district",
log_x=True, size_max=100, range_x=[0.1,0.600], range_y=[0,30])
试图转换列 - 没有帮助。
提前tnx
问题出在 Meeting_inv 和 pchanges_dax 列中的百分号。 pandas(并且巧妙地)将它们视为字符串——而不是整数。
要解决它,运行:
df["Meeting_inv"] = df.Meeting_inv.str.replace("%", "").astype(int)
df["pchanges_dax"] = df.pchanges_dax.str.replace("%", "").astype(int)
然后创建情节。
我正在尝试绘制带有百分比列的数据框,并在图表中快速抛出。
收到
TypeError: unsupported operand type(s) for /: 'str' and 'int'
列:
Meeting_inv pchanges_dax Unscheduled_orde pharmacy_nam dis yyyy/mm
0 1% 17% 5 x r 2011-1
1 2% 11% 1 x r 2011-2
2 5% 10% 7 x r 2011-6
3 10% 10% 5 x r 2011-7
4 2% 5% 14 x r 2011-8
代码:
import plotly.express as px
px.scatter(df3, x="Meeting_inventory_target", y="Unscheduled_orders", animation_frame="yyyy/mm", animation_group="pharmacy_name",
size="pchanges_dax", color="pharmacy_name", hover_name="district",
log_x=True, size_max=100, range_x=[0.1,0.600], range_y=[0,30])
试图转换列 - 没有帮助。
提前tnx
问题出在 Meeting_inv 和 pchanges_dax 列中的百分号。 pandas(并且巧妙地)将它们视为字符串——而不是整数。
要解决它,运行:
df["Meeting_inv"] = df.Meeting_inv.str.replace("%", "").astype(int)
df["pchanges_dax"] = df.pchanges_dax.str.replace("%", "").astype(int)
然后创建情节。