通过熊猫遍历整个群

时间:2019-09-23 12:57:12

标签: python pandas matplotlib

df = 

         id_easy    latitude    longitude
level_0                 
0        6454       11          3
0        6454       12          4 
2        2323       23          5
2        2323       23          7
3        25603      13          5 
3        141        14          6 

想要绘制:

  • 第一图:通过显示第一点,以一种颜色显示long lat的所有id_easy6454
  • 第二个图:通过显示第一个点,以其他颜色显示long lat的所有id_easy2323
  • ...

len(df)

中的逻辑相同

我的尝试:

for index_in_red in df.index.unique():
    plt.plot(df.loc[df.index != index_in_red,'longitude'],df.loc[df.index != index_in_red,'latitude'] ,
             color='silver', marker='o',linestyle='')

    plt.plot(df.loc[index_in_red,'longitude'],df.loc[index_in_red,'latitude']  ,
              color='maroon',marker='o',linestyle='')
    plt.show()

所需的输出:

enter image description here

1 个答案:

答案 0 :(得分:1)

for i in df.index.unique():
    plt.plot(df[df['id_easy'] != i]['longitude'],df[df['id_easy'] != i]['latitude'] ,
         color='silver', marker='o',linestyle='')

    plt.plot(df[df['id_easy'] != i]['longitude'],df[df['id_easy'] != i]['latitude'] ,
         color='maroon',marker='o',linestyle='')
    plt.show()