Data processing returns database python

On the code:

Import SqlHelper.MSSQL the MS AS
 Import   PANDAS PD AS
 IF  the __name__ == ' __main__ ' : 
     # connect to the database 
    MS = MS.MSSQL (= Host " .. *** *** *** ***. " , = User " ** " , pwd = " ** " , db = " ** " ) 

    # ############################### ########################## returns no header data 
    reslist = ms.ExecQuery ( " SELECT * from Version " )
     for X in reslist:
        print(X)
     # output: 
    # (. 1, '1.0.0.0', 'initial release') 
    # (2, '1.0.0.1', 'a new version, published 2019-10-09 16:35:00') 
    # (. 3, '1.0.0.2', None) 
    # (. 4, '1.0.0.3', None) 

    # ########################## ############################### return header has data DataFrame 
    DF = ms.ExecQueryToDataFrame ( " SELECT * from Version " )
     Print (df)
     # output: 
    #    the above mentioned id the Message version 
    # 0 1 1.0.0.0 initial version 
    # 1 2 1.0.0.1 The new version, released 2019-10-09 16:35:00 
    # 23 1.0.0.2                       None
    #None 1.0.0.3 4 3 
    
    # ########################################### ############## DataFrame traverse data, take version, message field 
    # mode a 
    for Row in df.itertuples ():
         Print (getattr (Row, ' Version ' ), getattr (Row, ' the Message ' )) 
     # output: 
    # 1.0.0.0 initial release 
    # 1.0.0.1 The new version, released 2019-10-09 16:35:00 
    # 1.0.0.2 None 
    # 1.0.0.3 None 
  
    # Second way 
    for i in the Range (0, len (DF)):
         Print (df.iloc [I] [' Version ' ], df.iloc [I] [ ' Message ' ])
     # output: 
    # 1.0.0.0 primary version 
    # 1.0.0.1 new version, published 2019-10-09 16:35:00 
    # 1.0.0.2 None 
    # 1.0.0.3 None 

    # ############################################ ############## row fetching second data 
    Print (df.iloc [. 1])    # two, left key, the right side is a value 
    # output: 
    # ID 2 
    # Version 1.0. 0.1 
    # the Message The new version, released 2019-10-09 16:35:00 
    # the Name: 1, dtype: Object 
     

    ################################################### ######## take second row message field value 
    Print (df.iloc [. 1] [ ' message ' ]) 
     # output: 
    # new version, published 2019-10-09 16:35:00
     
   

 

If it helps you, please sponsorship lollipops ~

Guess you like

Origin www.cnblogs.com/shurun/p/11956828.html