Advertisement
Guest User

Untitled

a guest
Mar 20th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. df = pd.read_csv(s_root + s_file,sep=";",skiprows=1,header=None)
  2. df = df.iloc[:-1,:]
  3. df[1] = df[1].str.strip()
  4. #######################
  5. # tranforma tudo em string
  6. df[6] = [str(x) for x in df[6]]
  7. #######################
  8. for x in df[1].unique():
  9.     try:
  10.         dfaux = df.loc[df[1]==x,:]
  11.         #######################
  12.         # filtra string. Note que mudei o df para dfaux tb
  13.         dfaux = dfaux.loc[dfaux[6]=='1',:]
  14.         # nao processa se for matriz em branco
  15.         if dfaux.shape[0] == 0:  
  16.             continue
  17.         #######################
  18.         dfaux[2] = dfaux[2].astype(int)
  19.         dfaux[4] = dfaux[4].astype(int)
  20.         dfaux[16] = dfaux[16].astype(int)
  21.         dfaux[17] = dfaux[17].astype(int)
  22.         dfaux[18] = 0
  23.         dfaux.loc[dfaux[10]==1,18]=1
  24.         dfaux.loc[dfaux[14]==1,18]=2
  25.         dfaux.loc[dfaux[15]==1,18]=3
  26.         print 'Step 1='+ dfaux.iloc[0,1]
  27.         dfaux = dfaux.loc[:,[1,0,5,2,3,4,16,17,18]]
  28.         dfaux = dfaux.sort_values(by=2).reset_index(drop=True)
  29.         print 'Step 2='+dfaux.iloc[0,1]
  30.     except Exception as e:
  31.         print e
  32.         print x
  33.         print dfaux
  34.         raise
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement