首页 > 解决方案 > 如何为此数据框创建散点图?

问题描述

下面是我的数据集。我无法使用以下方法为此创建散点图:

data.plot.scatter(x="",y="")

在此处输入图像描述

标签: pythonpandasmatplotlibplotscatter

解决方案


您不能通过使用要在图中使用的项目的索引来简单地对列的内容进行切片。您可以使用 matplotlib 框架并使用 lambda 函数对列表进行切片:

import matplotlib.pyplot as plt
plt.scatter(df['R'], df['Vol'].apply(lambda x: x[0]))

推荐阅读