import pandas as pd
import matplotlib.pyplot as plot



def changetoProtocol():
    #reading tcp.csv file generated by wireshark 
    df = pd.read_csv('tcp.csv')
    #group by the protocols to analyze the count of packets by each protocol
    protocolVsPacket = df.groupby("Protocol").Source.count()
    #print(protocolVsPacket)

    #plot the bars
    p = protocolVsPacket.plot(kind="bar")
    p.set_title("No of packets vs Protocol")
    p.set_xlabel("Protocol")
    p.set_ylabel("Number of Packets")

    #divide into patches 
    rects = p.patches

    #labels is the 1 D Array of protocolVsPacket
    labels = list(protocolVsPacket)
    #print(labels)

    for rect, label in zip(rects, labels):
        height = rect.get_height()
        #print(height)
        #print(rect.get_x())
        #print(rect.get_width)
        p.text(rect.get_x() + rect.get_width() / 2, height + 5, label,ha='center', va='bottom')
    plot.show()
 
changetoProtocol()

