{"id":990,"date":"2022-08-05T00:29:48","date_gmt":"2022-08-04T23:29:48","guid":{"rendered":"https:\/\/blog.thomarite.uk\/?p=990"},"modified":"2022-08-05T00:29:48","modified_gmt":"2022-08-04T23:29:48","slug":"pandas","status":"publish","type":"post","link":"https:\/\/blog.thomarite.uk\/index.php\/2022\/08\/05\/pandas\/","title":{"rendered":"Pandas"},"content":{"rendered":"\n<p>This is something I have heard about in the past but never used. So this week, as finally decided to write a script to help me to find the peers of flapping ports, learned about pandas from first time. I used another script as &#8220;inspiration&#8221; and after seeing it was using pandas, I decided to read a bit about it and give it a go.<\/p>\n\n\n\n<p>The main type is the <a href=\"https:\/\/pandas.pydata.org\/docs\/reference\/api\/pandas.DataFrame.html\">DataFrame<\/a>. In my head, pandas is just a library to deal with  CSV, spreadsheets, etc like when you use a program like libreoffice. And this <a href=\"https:\/\/www.geeksforgeeks.org\/selecting-rows-in-pandas-dataframe-based-on-conditions\/?ref=lbp\">page<\/a>, gave me the hints for creating the query I wanted to make.<\/p>\n\n\n\n<p>So at the end I have my very basic <a href=\"https:\/\/github.com\/thomarite\/scripts\/blob\/main\/flapping-peer.py\">script<\/a> but saves me time logging to each device and find the peer port. <\/p>\n\n\n\n<p>Of course, there are different ways to tackle this problem, but in my environment, the source of truth for links is in a file. You could have that info in the port description too, or in a database, etc.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ python3 flapping-peer.py -f flapping-list.txt\n\nResult:\nSW1 Ethernet1\/1 SW2 Ethernet1\/1\nSW1 Ethernet1\/4 SW2 Ethernet1\/4\n\n$  \n$ cat flapping-list.txt \nSW1,Ethernet1\/1\nSW2,Ethernet1\/4\n$\n$ cat patching-file.csv \nSite,Source Device,Source Interface,Destination Device,Destination Interface,Media\nA,SW1,Ethernet1\/1,SW2,Ethernet1\/1,SMF\nA,SW1,Ethernet1\/2,SW2,Ethernet1\/2,SMF\nA,SW1,Ethernet1\/3,SW2,Ethernet1\/3,SMF\nA,SW1,Ethernet1\/4,SW2,Ethernet1\/4,SMF\nA,SW1,Ethernet1\/5,SW2,Ethernet1\/5,SMF\n$ \n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This is something I have heard about in the past but never used. So this week, as finally decided to write a script to help me to find the peers of flapping ports, learned about pandas from first time. I used another script as &#8220;inspiration&#8221; and after seeing it was using pandas, I decided to &hellip; <a href=\"https:\/\/blog.thomarite.uk\/index.php\/2022\/08\/05\/pandas\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Pandas&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,25],"tags":[],"class_list":["post-990","post","type-post","status-publish","format-standard","hentry","category-programming","category-python"],"_links":{"self":[{"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/posts\/990","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/comments?post=990"}],"version-history":[{"count":1,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/posts\/990\/revisions"}],"predecessor-version":[{"id":991,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/posts\/990\/revisions\/991"}],"wp:attachment":[{"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/media?parent=990"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/categories?post=990"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/tags?post=990"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}