Python 基于列id在dataframe上打印数据

Python 基于列id在dataframe上打印数据,python,plot,dataframe,Python,Plot,Dataframe,我必须用Python绘制数据帧中的数据。我的数据框是: df = time lat lon sessions 0 2014-05-06 06:28:01.525882+00:00 48.787982 11.383787 242 1 2014-05-06 06:28:22.530717+00:00 48.788082 11.383300 242 2 201

我必须用Python绘制数据帧中的数据。我的数据框是:

df = 
    time                                lat         lon         sessions
0   2014-05-06 06:28:01.525882+00:00    48.787982   11.383787   242
1   2014-05-06 06:28:22.530717+00:00    48.788082   11.383300   242
2   2014-05-06 06:29:48.550528+00:00    48.788043   11.382594   242
3   2014-05-06 06:30:05.554449+00:00    48.788040   11.381211   242
4   2014-05-06 06:30:17.557220+00:00    48.788188   11.381085   242
5   2014-05-06 06:30:27.559540+00:00    48.788753   11.381086   242
6   2014-05-06 13:17:46.022015+00:00    48.786922   11.337102   243
7   2014-05-06 13:17:57.023334+00:00    48.786888   11.338405   243
8   2014-05-06 13:18:07.024034+00:00    48.786746   11.339067   243
9   2014-05-06 13:18:18.025342+00:00    48.786281   11.341296   243
10  2014-05-06 13:18:28.026042+00:00    48.785346   11.344839   243
11  2014-05-06 13:18:38.027245+00:00    48.784328   11.348702   243

我想创建一个绘图,其中不同的
会话
具有不同的颜色

也许这是最好的解决方案

groups = data.groupby('sessions')
fig, ax = plt.subplots()
ax.margins(0.05) # Optional, just adds 5% padding to the autoscaling
for name, group in groups:
    ax.plot(group.lat, group.lon, marker='.', linestyle='', ms=12, label=name)
ax.legend()

plt.show()

也许这是最好的解决方案

groups = data.groupby('sessions')
fig, ax = plt.subplots()
ax.margins(0.05) # Optional, just adds 5% padding to the autoscaling
for name, group in groups:
    ax.plot(group.lat, group.lon, marker='.', linestyle='', ms=12, label=name)
ax.legend()

plt.show()

如果我没弄错的话,您可以根据列而不是行更改颜色。为此,您需要根据
会话
值将DF细分为更小的DF。i、 e.
df[df['sessions']==242]
谢谢,我想避免这种情况,但我想这是唯一的办法。如果我没弄错的话,你可以根据列而不是行来更改颜色。为此,您需要根据
会话
值将DF细分为更小的DF。i、 e.
df[df['sessions']==242]
谢谢,我想避免这种情况,但我想这是唯一的办法。