Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. # Load the files using pandas
  2. import pandas as pd
  3.  
  4. df = pd.read_csv("/Users/serafeim/Downloads/Testfile.csv")
  5.  
  6. # Get the desired elements based on 'Time' column
  7. mask = df['Time'] < 0.1
  8.  
  9. # Write the new file
  10. df_1 = df[mask] # or directly use: df_1 = df[df['Time'] < 0.1]
  11.  
  12. # save it
  13. df_1.to_csv("Testfile1.csv")
  14.  
  15. print(df_1)
  16. No. Time Length
  17. 0 1 0.000000 146
  18. 1 2 0.006752 116
  19. 2 3 0.019767 156
  20. 3 4 0.039635 144
  21. 4 5 0.060090 147
  22. 5 6 0.069165 138
  23. 6 7 0.079700 133
  24. 7 8 0.099397 135
  25.  
  26. #For 0.1 to 0.2 applying 2 logical conditions
  27. df_2 = df[(df['Time'] > 0.1) & (df['Time'] < 0.2)]
  28.  
  29. import pandas as pd
  30.  
  31. lower = [0,0.1,0.3]
  32. upper = [0.1,0.2,0.4]
  33.  
  34. df = pd.read_csv("/Users/serafeim/Downloads/Testfile.csv")
  35.  
  36. for k,(i,j) in enumerate(zip(lower,upper)):
  37. # i and j will get the lower and upper values
  38. temp = df[(df['Time'] > i) & (df['Time'] < j)]
  39. temp.to_csv("/Users/serafeim/Downloads/aaa_{}".format(k))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement