【问题标题】:csv importing latitude column as float need it to be numericcsv将纬度列导入为浮点数需要它是数字
【发布时间】:2021-01-02 13:22:55
【问题描述】:

导入 csv 文件后,我使用streamlit 绘制它。

问题是为 lat/long 导入的列类型是浮点数。如何将此浮点数转换为可读格式?

我使用 pd.tu_numeric() 或 .apply(np.int64) 尝试了一些技巧,但没有任何效果。

new_df['latitude'] = data['latitude'].dropna().apply(np.int64)
new_df['longitude'] = data['longitude'].dropna().apply(np.int64)


pd.to_numeric(data, errors='coerce')
st.map(data)

感谢您帮助初学者

【问题讨论】:

  • Lat/Lon 通常指定为浮点数,而不是整数。为什么你认为你需要改成整数?
  • 因为streamlit界面告诉我“StreamlitAPIException: 纬度和经度数据必须是数字”
  • 将浮点数(数字)转换为数字不会修复该错误消息。我会保持浮点数不变,但请检查您的数据中是否有任何缺失值。 NaN 也是“不是数字”

标签: python-3.x floating-point integer geo streamlit


【解决方案1】:

尝试使用下面的sn-p

new_df['latitude']=pd.to_numeric(new_df['latitude']) 
new_df['longitude']=pd.to_numeric(new_df['longitude])

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_numeric.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-08
    • 2013-05-06
    • 2021-03-31
    • 2013-09-23
    • 1970-01-01
    • 1970-01-01
    • 2020-04-22
    • 1970-01-01
    相关资源
    最近更新 更多