0

I am using python 3.6.5 and I am getting this problem:

df = pd.DataFrame({'a' : [1,2,3] , 'b' : [4,5,7]} , dtype = np.float64)

and if I do any kind of division, for instance

df['a']/2.0 = 0   0
              1   1
              2   2
              Name: a, dtype: float64

And actually even if I try to build a dataframe using an array containing decimals, pd.DataFrame is turning everything into integer, eventhough it says that the dtype is float64. Thanx for ur help

Alaa J E
  • 31
  • 5
  • I can't reproduce, works for me. Python 3.6.5, pandas 0.23.0 – user3483203 Jul 26 '18 at 15:58
  • Did you by any chance ever set `np.float64 = int`? Because that would give you the initial behavior, but even so, dividing by a float should change the column. – user3483203 Jul 26 '18 at 15:59
  • No at all. I can't understant this beavior of pandas dataframe and pandas series. Even when Iam doing this for instance value = df['a'].values/3 value outpt : array([0.33333333, 0.66666667, 1. ]) and then I tr to do something like that pd.Series(data = value, dtype = np.float64) The resulting series is only full of 0's – Alaa J E Jul 26 '18 at 16:16
  • Really weird behavior. If you open a brand new terminal python3 and type exactly that code, does it still happen? – rafaelc Jul 26 '18 at 16:28
  • Really weired, yes It works in python terminal... So I don't know what's the problem with jupyter – Alaa J E Jul 26 '18 at 16:33
  • It works in a terminal. where could the problem come from as I am working with jupyter notebook. I dont know because I tried everything.... – Alaa J E Jul 26 '18 at 16:42

0 Answers0