import pandas as pd
import matplotlib.pyplot as plt
# Here we subset your dataframe where the temperature is 90, which will give you a
# boolean array for your dataframe.
temp_90 = df['Temperature'] == 90
# Apply your boolean against your dataframe to grab the correct rows:
df2 = df[temp_90]
# Now plot your scatter plot
plt.scatter(x=df2['ice_cream_sales'] y=df2['Temperature'])
plt.show()
最简单的方法是创建您感兴趣的值子集的数据帧
假设您有一个数据框df,其中包含“冰淇淋销售”、“温度”列
我不知道为什么要绘制销售=5美元、温度=90的散点图。这会给你一个数据点
相反,您可以使用不等式进行子集划分:
另外,请注意不要在变量的和上都应用子集,否则您将伪造您试图用散点图显示的任何关系
相关问题 更多 >
编程相关推荐