I have this code to extract some data from a csv. I can extract the data with no problem but I would like to change the numpy array from a int to a float. I know that the argument to do that is dtype=np.float32 but I keep having an error message when I do include this argument:
This is the code:
import numpy as np
import pandas as pd
rainfall=pd.read_csv('Seattle2014.csv')['PRCP'].values
inches=rainfall / 254
inches.shape
#...
rainy=(inches >0)
summer=(np.arange(365)-172<90) &(np.arange(365)-172>0)
print ("Mediam precipitation on rainy days in 2014 (inches): ",np.median(inches[rainy]))
print ("Mediam precipitation on summer days in 2014 (inches): ",np.median(inches[summer]))
print ("Maximum precipitation on summer days in 2014 (inches): ",np.max(inches[summer]))
print ("Median precipitation on non-summer days in 2014 (inches): ",np.median(inches[rainy & ~summer]))
This is the code with the argument:
rainy=(inches >0)
summer=(np.arange(365)-172<90) &(np.arange(365)-172>0)
print ("Mediam precipitation on rainy days in 2014 (inches): ",np.median(inches[rainy], dtype=float))
And I do get this error message:
TypeErrorTraceback (most recent call last) <ipython-input-136-29b7a435cc0e> in <module>()
1 rainy=(inches >0)
2 summer=(np.arange(365)-172<90) &(np.arange(365)-172>0)
----> 3 print ("Mediam precipitation on rainy days in 2014 (inches): ",np.median(inches[rainy], dtype=float))
4 print ("Mediam precipitation on summer days in 2014 (inches): ",np.median(inches[summer]))
5 print ("Maximum precipitation on summer days in 2014 (inches): ",np.max(inches[summer]))
TypeError: median() got an unexpected keyword argument 'dtype'
How can I solve this problem?
float(...)..median()and.max()and so on methods on the dataframe? You can print whatever representation you choose regardless.rainfall=pd.read_csv('Seattle2014.csv')['PRCP'].values.astype(np.float)