0

I have a dataframe like this:

   VID  CID  PID8  PID6
0    1  379     3     3
1    2  160     2     2
2    3  334     3     3
3    7  176     1     3
4    8  237     3     2

I need to find the changes from PID6 to PID8

I have tried this so far:

import pandas as pd
vp = pd.read_csv('votingpattern.csv') 
print vp.head()
print type(vp)
for v in VID:
    if vp.PID6 == 1 & vp.PID8 == 2:
        C12 += 1
    elif vp.PID6 == 1 & vp.PID8 == 3:
        C13 += 1
    elif vp.PID6 == 2 & vp.PID8 == 3:
        C23 += 1
    elif vp.PID6 == 2 & vp.PID8 == 1:
        C21 += 1
    elif vp.PID6 == 3 & vp.PID8 == 1:
        C31 += 1
    else vp.PID6 == 3 & vp.PID8 == 2:
        C32 += 1

MyList = [C12,C13,C23,C21,C31,C32]
print max(MyList)

But I can't seem to access the entire row of dataframe and iterate over each row. Can anyone tell me where am I going wrong? Thanks!

Chica_Programmador
  • 107
  • 1
  • 3
  • 16
  • http://stackoverflow.com/questions/19120489/compare-two-files-report-difference-in-python –  Nov 15 '16 at 01:13
  • You can post it as and answer and accept it in a bit. –  Nov 15 '16 at 01:26
  • and you should look into for loops. They will help you shorten that code a LOT! –  Nov 15 '16 at 01:26
  • I need to gain special insights about the changes hence did it this way, so that I may access individual variable for a specific pattern. Can loop help me do the same? – Chica_Programmador Nov 15 '16 at 01:29
  • for i in range (0,n): if vp.PID6[i] == 1 & vp.PID8[i] == 2: C12 += 1 elif vp.PID6[i] == 1 & vp.PID8[i] == 3: C13 += 1.......... Adding a loop worked...@AllDani.com Thanks! – Chica_Programmador Nov 15 '16 at 04:06
  • No problem. You can post that as an answer, and accept it. –  Nov 15 '16 at 14:01

0 Answers0