Find weight differences
1. import pandas as pd2. w07 = pd.read_csv('w07.csv')
> tried to make the name most simpliest
3. w08 = pd.read_csv('data/w08.csv')
4. w07_w = w07[['pid', 'w07C105']]
5. w08_w = w08[['pid', 'w08C105']]
> index columns that we are going to use
> single quotations for columns
6. w0708_w = w07_w.merge (w08_w, how = 'inner', on='pid')
> merge wave 7-8 based on pid, by inner
> inner means both of the columns should have pid
7. w0708_w
> display what data have merged
8. w0708_w['diff'] = w0708_w['w08C105'] - w0708_w['w07C105']
> a variable of differences is made by subtractions
9. w0708_w['diff >= 5'] = ( abs (w0708_w['diff]) >= 5 )
10. w0708_w
> show a new column, diff > = 5
11. w0708_d5 = w0708_w[w0708_w['diff >= 5']] == True ]
12. w0708_w5.to_excel('w0708_w5.xlsx')
> extract columns to excel file
Comments
Post a Comment