Guest User

Untitled

a guest
May 26th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. df.eval('I = (G * H) / 10000', inplace=True)
  2.  
  3. TypeError: unsupported operand type(s) for /: 'object' and '<class 'int'>'
  4.  
  5. df.eval('I = G * H', inplace=True)
  6.  
  7. my_df.eval('I = (A * B)', inplace=True)
  8. print(my_df.I)
  9. >>> 0 8
  10. >>> Name: I, dtype: object
  11.  
  12. import pandas as pd
  13.  
  14.  
  15. columns = ['A', 'B', 'C']
  16. my_df = pd.DataFrame(columns=columns)
  17. my_df.loc[len(my_df)] = [2, 4, 5]
  18. print(my_df.dtypes)
  19.  
  20. >>> A object
  21. >>> B object
  22. >>> C object
  23. >>> dtype: object
  24.  
  25. # Convert from object to int.
  26. my_df[columns] = my_df[columns].astype(int)
  27.  
  28. my_df.eval('I = (A * B) / 10000', inplace=True)
  29. print(my_df)
  30. >>> A B C I
  31. >>> 0 2 4 5 0.0008
Add Comment
Please, Sign In to add comment