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
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)