从 Dataframe (python/pandas) 的列中绘制多行?

Plotting multiple lines from columns of Dataframe (python/pandas)?

我有大量(约 100 万)数据集,看起来像这样...

Age    Wavelength    Luminosity

1      96            100
1      97            150
1      98            100
2      96.5          90
2      97            160
2      97.5          120
...

我目前在数据框中有它,想绘制所有年龄组的波长与光度的关系图。我如何在一张图表上获取每个年龄段的图表?

您可以使用pandas.core.groupby.DataFrameGroupBy.plot

In[1]: import pandas as pd

In[2]: import numpy as np

In[3]: dataset = pd.DataFrame({"Age": np.random.random_integers(1, 5, 100), "Wavelength": np.random.uniform(90, 100, 100), "Luminosity": np.random.random_integers(5, 15, 100) * 10})

In[4]: dataset.groupby("Age").plot(x="Wavelength", y="Luminosity", kind="scatter")
Out[4]: 
Age
1    Axes(0.125,0.1;0.775x0.8)
2    Axes(0.125,0.1;0.775x0.8)
3    Axes(0.125,0.1;0.775x0.8)
4    Axes(0.125,0.1;0.775x0.8)
5    Axes(0.125,0.1;0.775x0.8)
dtype: object