How can I replace values from one text file with other values from another text file only if certain values are equal?

后端 未结 1 1544
臣服心动
臣服心动 2021-01-23 09:23

I have a file called finalscores.txt and I want to to create a python script which will open it and read in values from two separate columns.

This is my

相关标签:
1条回答
  • 2021-01-23 09:58

    If you read the two csvs into pandas DataFrame objects, then it is a matter of updating the second one with values from the first. The update method requires the two dataframes to have a similar index.

    import pandas as pd                                                                                                                                                                 
    
    df = pd.read_csv('finalscores.csv', sep=r'\s+', engine='python', skipfooter=1)                                                                                                                   
    df = df.ix[:, ['Atom', 'avgppm']]                                                                                                                                                   
    pink = pd.read_csv('pinkH1_ppm.txt', sep=r'\s+', header=None, names=('Atom', 'avgppm', 'x'))                                                                                               
    
    df.set_index('Atom', inplace=True)                                                                                                                                                  
    pink.set_index('Atom', inplace=True)                                                                                                                                                
    pink.update(df)     
    
    0 讨论(0)
提交回复
热议问题