Advertisement
m8_

divide int by 100

m8_
May 6th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. import pandas as pd
  2.  
  3. # create dictionary of data
  4. data = {'Local ID': {0: 'A68',
  5. 1: 'A69',2: 'A70',3: 'A71',4: 'A72',5: 'A73',6: 'A74',7: 'A75',8: 'A76',9: 'A77',10: 'A78',11: 'A79',12: 'A80',13: 'A81',
  6. 14: 'A82',15: 'A83',16: 'A84',17: 'A85',18: 'A86',19: 'A87',20: 'A88',21: 'A89',22: 'A90',23: 'A91'},
  7. 'Initial Percent': {0: 90,1: 50,2: 50,3: .3,4: 95,5: 70,6: 80,7: .9,8: 80,9: 95,10: 50,11: 70,12: 70,13: 90,14: 90,15:
  8. 80,16: 60,17: 80,18: 80,19: 80,20: 50,21: 70,22: 40,23: 30}}
  9.  
  10. # create dataframe from dictionary
  11. df = pd.DataFrame.from_dict(data)
  12.  
  13. # if value is int, divide by 100
  14. df.loc[:, 'Initial Percent'] = df.loc[:, 'Initial Percent'].apply(lambda x: x/100 if x % 3 == 0.0 else x)
  15.  
  16. ## also tried the following
  17. #df.loc[:, 'Initial Percent'] = df.loc[:, 'Initial Percent'].apply(lambda x: x/100 if isinstance(x, int) else x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement