Итерация сюжетов по группе по пандам - PullRequest
0 голосов
/ 23 сентября 2019
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_easy 6454 в один цвет, показывая первые точки
  • второй график: все long и lat значения id_easy 2323 другого цвета, показывая первые точки
  • ...

та же логика в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 Ответ

1 голос
/ 23 сентября 2019
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()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...