Merging two .csv files python-pandas
Question: I have two .csv files with the same initial column-header:

    
    
    NAME         RA        DEC  Mean_I1  Mean_I2  alpha_K24 class  alpha_K8 class.1      Av  avgAv
    Mon-000101  100.27242   9.608597   11.082   10.034       0.39     I      0.39       I              31.1      31.1
    Mon-000171  100.29230   9.522860   14.834   14.385       0.45     I      0.45       I          33.7      33.7
    

and

    
    
           NAME        Sdev_I1        Sdev_I2
     Mon-000002,         0.023,   0.028000001,
     Mon-000003,   0.016000001,   0.016000001,
    

I want to merge the two together so that the 'NAME' columns match up,
basically just add the two Sdev_I1/Sdev_I2 to the end of the first sample.
I've tried...

    
    
    import pandas as pd
    
    df1 = pd.read_csv('h7.csv',sep=r'\s+')
    df2 = pd.read_csv('NEW.csv',sep=r'\s+')
    
    df = pd.merge(df1,df2)
    
    df.to_csv('Newh7.csv',index=False)
    

but it's printing the 'NAME' twice and everything seems to be out of order and
with a lot of added zeroes as well. I thought I had solved this one awhile
back, but I've totally lost it. Help would be appreciated. Thanks.

Here's the output file:

    
    
    NAME,RA,DEC,Mean_I1,Mean_I2,alpha_K24,class,alpha_K8,class.1,Av,avgAv,Sdev_I1,Sdev_I2
    


Answer: Seems you didn't strip the comma symbol in the second csv, you might try to
use converters to convert them:

    
    
    In [81]: converters = {
                 'NAME': lambda x:x[:-1], 
                 'Sdev_I1': lambda x: float(x[:-1]),     
                 'Sdev_I2': lambda x: float(x[:-1])
             }
    
    In [82]: pd.read_csv('NEW.csv',sep=r'\s+', converters=converters)
    Out[82]: 
             NAME  Sdev_I1  Sdev_I2
    0  Mon-000002    0.023    0.028
    1  Mon-000003    0.016    0.016
    

