Advertisement
KillianMills

round_nums.py

Dec 5th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. import pandas as pd
  2.  
  3.  
  4. input_file = "input.csv"
  5. output_file = "output.csv"
  6.  
  7. INTER = "Inter"
  8. INTRA = "Intra"
  9.  
  10. def round_nums(val):
  11.     copy = round(val, 4)
  12.     if copy < val:
  13.         copy = copy + 0.0001
  14.     return copy
  15.  
  16. def convert(input_df):
  17.     input_df[INTER] = input_df[INTER].apply(round_nums)
  18.     input_df[INTRA] = input_df[INTRA].apply(round_nums)
  19.     return input_df
  20.  
  21. input_df = pd.read_csv(input_file)
  22. output_df = convert(input_df)
  23. output_df.to_csv(output_file, index=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement