By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,777 Members | 1,311 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,777 IT Pros & Developers. It's quick & easy.

Filtering a large data file

P: 2
Hi I have a large data file and I'm only interested in rows with specific x values of 4.125 as shown below. Now because the value of 4.125 relates to the stop position of the ion, the corresponding start position is also of interest to me and I want to keep this information in the array. How do I write a program which effectively finds the x stop position of 4.125 and retains the ion start position? I have attached the data file I'm using.

This is the code I have developed so far but does not work:

Expand|Select|Wrap|Line Numbers
  1. import pandas as pd 
  2. import numpy as np
  3.  
  4. opts = pd.read_csv('Ambre_2.dat',sep = ',', low_memory = False)
  5. df = pd.DataFrame(opts)
  6.  
  7. X = df.iloc[:,3]
  8. IonN = df.iloc[:,0]
  9. tol = 1e-6
  10. Fltr = 4.125
  11.  
  12. filterreddata = df[abs(df.X-Fltr)<tol,:]
  13. filteredions = df(np.in1d(df.IonN, filterreddata.IonN), :]
  14. filteredions[2:2:end, :] = []
  15. f = open('ions.csv', 'w')
  16. f.write(tabulate(filteredions))
  17. f.close()
Jun 29 '18 #1
Share this Question
Share on Google+
2 Replies


P: 2
In the example shown below I would be interested in keeping the information of ion # 3849096.

"Ion N","Mass","Charge","X","Y","Z","Azm","Elv","KE" 3849094,0.00054858,-1,66.5216,-51,-3.8,-180,88.7,18160 3849094,0.00054858,-1,27.3925,30.3532,-4.07076,-177.1,41.5494,17697.2 3849095,0.00054858,-1,66.5216,-51,-3.7,-180,88.7,18160 3849095,0.00054858,-1,26.6277,31.0039,-3.91402,-177.096,40.8293,17699.4 3849096,0.00054858,-1,66.5216,-51,-3.6,-180,88.7,18160 3849096,0.00054858,-1,4.125,44.9887,-2.47517,-176.363,25.715,17711.1
Jun 29 '18 #2

Post your reply

Sign in to post your reply or Sign up for a free account.