我目前正在为我的CS类做一个项目,我正在分析一个CVS文件,其中有华盛顿州的电动汽车数量。我已经完成了大部分的图形,但我试图使所有车辆在华盛顿的散点Map图,因为它包括在CSV的经度和纬度。最初它是一个字符串值,但我已经分离的数据,并将它们转换为浮动的Map。在测试的时候,我已经确认,当使用.dtypes时,它说我的值是浮点数,并且我在运行它时没有得到任何错误。值得注意的是,该文件超过153k个整数,大约20 MB。我的主要问题是,为什么当我使用plotyl网站的默认代码时,它显示Map,但当我尝试自己的代码时,它显示一个空白的浏览器页面。
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
1条答案
按热度按时间kulphzqa1#
我能够找出问题与我的CS老师调查后,空白窗口,它给了一个错误,表明我的Latt和Long被切换.我现在可以绘制我的点.