python - 嵌套字典有问题
问题描述
我在嵌套字典的这一部分遇到了一些麻烦。我尝试了很多不同的东西,但我不断收到这个错误:
complete_dict[county]['price'] = int(item.get(average_price))
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
这是我到目前为止的说明和代码。
# Finally you will find how much the housing prices have changed in each county.
# You can get this number by finding the difference between the average home price
# in April 1996 and the average home price in April 2015.
# The values should mostly be positive since home prices have increased since 1996.
# We are expecting to see float values.
# todo Put code here to find the housing prices.
for item in home_data:
price = int(item.get('Home Price', 0))
county = item.get('county')
if county in complete_dict:
price1 = complete_dict[county].get('price', 0)
average_price = price1-price
complete_dict[county]['price'] = int(item.get(average_price))
else:
complete_dict[county] = {'price': int(price)}
以下是关于 complete_dict 的更多说明: 字典创建 # 使用县名作为键创建字典。# 从医院数据集中,您将要添加一个县的所有 total_licensed_beds。# 从 COVID 数据集中,您将要添加活动案例。# 从 Housing 数据集中,您将需要房价之间的差异(2015 - 1996)。# 你的数据结构如下所示: # {'county1': {'beds': [1], 'cases': [2], 'housing': [3]}, 'county2': {'beds': [1],“案例”:[2],“住房”:[3]}}
解决方案
推荐阅读
- windows - Windows 文件夹
- r - 覆盖 ggplot 的范围以指示正确的中断
- ruby-on-rails - 一个模型必须链接到另一个模型还是可以链接到基于相同模型的表?
- javascript - 如何在我的组件中重复使用 Vuetify 颜色?
- python - Apache NiFi:ExecuteStreamCommand 生成两个流文件
- javascript - Markdown-to-jsx 不接受源
- c# - Restsharp JSON 响应搜索
- javascript - 在 React 中持久化内存
- reactjs - 在 React 中返回地图项时显示一次控制所有内容的滑块
- c# - 在 excel C# .NET 的末尾插入行