简体   繁体   English

如何为此 dataframe 创建散点 plot?

[英]How do I create a scatter plot for this dataframe?

Below is my dataset.下面是我的数据集。 I can't create a scatter plot for this using:我无法为此使用以下方法创建散点图 plot:

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

在此处输入图像描述

Your DataFrame contains lists in the "Vol" column, so to plot it, you will need to somehow get the values from them.您的 DataFrame 包含“Vol”列中的列表,因此对于 plot 它,您需要以某种方式从中获取值。 Let's assume you want to plot R and the first value in Vol.假设您想要 plot R 和 Vol 中的第一个值。 You can try something like this:你可以尝试这样的事情:

plt.scatter(x=df.R, y=df.Vol.apply(lambda y: y[0]))

You can't simply slice the content of the column by using the index of the item you want to use in the plot.您不能使用 plot 中要使用的项目的索引来简单地对列的内容进行切片。 You can use the matplotlib framework and slice the list using a lambda function:您可以使用 matplotlib 框架并使用 lambda function 对列表进行切片:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM