我目前正在为我的计算机科学课程做一个项目,我正在分析包含华盛顿州电动汽车数量的 CVS 文件。我已经完成了大部分图表,但我试图绘制华盛顿所有车辆的散点图,因为它在 CSV 中包含经度和纬度。最初它作为一个字符串值出现,但我已经分离了数据并将它们转换为地图的浮点数。在测试时,我已经确认,在使用 .dtypes 时,它说我的值是浮点数,并且在运行它时我没有收到任何错误。值得注意的是,该文件超过 153k 个整体,大约 20 MB。我的主要问题是为什么当我使用plotyl网站上的默认代码时它会显示地图,但是当我尝试我自己的代码时它会显示一个空白的浏览器页面。
import pandas as pd
import os
import plotly.express as px
import plotly.io as pio
os.chdir('/Users/dylandeforrest/cs projects/')
wash_df = pd.read_csv('Electric_Vehicle_Population_Data.csv')
#Loading in my data set
pio.renderers.default = 'browser'
unwanted = ["VIN (1-10)", "State", "Clean Alternative Fuel Vehicle (CAFV) Eligibility", "Electric Range", "Base MSRP", "DOL Vehicle ID", "Electric Utility", "2020 Census Tract"]
for i in unwanted:
del wash_df[i]
wash_df = wash_df.dropna()
wash_df[['point','Latt', 'Long']] = wash_df['Vehicle Location'].str.split(' ', expand=True)
del wash_df['point']
wash_df['Latt'] = wash_df['Latt'].str[1:]
wash_df['Long'] = wash_df['Long'].str[:-1]
wash_df['Latt'] = wash_df.Latt.astype(float)
wash_df['Long'] = wash_df.Long.astype(float)
fig = px.scatter_mapbox(wash_df, lat="Latt", lon="Long", hover_name="Make",zoom=3, height=300)
fig.update_layout(mapbox_style="open-street-map")
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
这就是我到目前为止所拥有的。我没有收到任何错误,它说我的 Latt 和 Long 数据类型都是 float64。我错过了什么?
原始文件:https://catalog.data.gov/dataset/electric-vehicle-population-data
您可以链接原始数据集以便我看一下吗?