python - NameError:名称“x1”未在加利福尼亚住房数据中定义
问题描述
这是我的代码:
import pandas as pd
url = 'https://raw.githubusercontent.com/subhadipml/California-Housing-Price-Prediction/master/housing.csv'
df = pd.read_csv(url)
df
#Subset all rows where ocean_proximity is equal to NEAR BAY. Call this variable x1.
df['ocean_proximity'] = df['ocean_proximity'].str.replace('NEAR BAY', 'x1')
#when I try to print x1, it shows error
print(x1.shape)
输出:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-39-6e7c2a59f460> in <module>()
1 df['ocean_proximity'] = df['ocean_proximity'].str.replace('NEAR BAY', 'x1') #Subset all rows where ocean_proximity is equal to NEAR BAY. Call this variable x1.
----> 2 print(x1.shape)
NameError: name 'x1' is not defined
谁能告诉我有什么问题?
解决方案
x1 = df[df['ocean_proximity'] == "NEAR BAY"]
x2 = df[df['ocean_proximity'] == "<1H OCEAN"]
#Make a histogram of x1 with nice titles, axes labels and colored blue.
#Make a histogram of x1 with nice titles, axes labels and colored blue.
import seaborn as sns
kwargs = dict(hist_kws={'alpha':.6},kde_kws={'linewidth':2})
plt.figure(figsize=(10,7),dpi=80)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-39-ba84939e49fe> in <module>()
1 #plot
2 kwargs = dict(hist_kws={'alpha':.6},kde_kws={'linewidth':2})
----> 3 plt.figure(figsize=(10,7),dpi=80)
NameError: name 'plt' is not defined
plt有什么问题?
推荐阅读
- html - 在 Mozilla 浏览器上图像显示为空白
- design-patterns - 如何获取用户权限数据
- android - 在列表元素中插入竖线
- java - 可以从浏览器获得响应,但 401 未授权来自 resttemplate
- reactjs - 警告是 React js 中的配置
- c# - 遇到分号后停止解析的正则表达式
- python-3.x - 在 MacOSX 上安装 Python 模块
- laravel - 如何使用 Laravel 在下拉列表中显示数据库中的选定值?
- android - 如何使用 Edittext 和下方的按钮调整 BottomSheet 的大小?
- laravel - 获取路由组内的路由时要传递给 route() 的正确字符串