I created a multi-indexed DataFrame wherein I used groupby with mean.
On checking data type of any particular value
(using ChkVlu = df.loc['Index1'].loc['index2'].loc['requiredcolumn'])
I get data type to be numpy.float64. I require the data type to native python float.
If I use ChkVlu = float(ChkVlu) then only one value at a time gets converted from float64 to float, however on using df = df.astype(float) for entire DataFrame I still get data type to be numpy.float64.
I used df = df.astype(float, copy=False) as well as df = df.astype(float, copy=True) but still getting float64 rather than float.
Please help me in converting float64 type DataFrame to float.
Edit1 : Posting the code here where AnnualData.csv has index 1 and index2 as 1st 2 columns and year-month combination as next set of columns in format of 2001-01, 2001-02, 2001-03 ....... 2016-09, 2016-10, 2016-11 with numerical data in each row. I am converting data in quarters with column names having q1, q2 and so on with mean value of each quarter.
df = pd.read_csv(‘AnnualData.csv')
df.set_index(['index1, 'index2'],inplace = True)
def quarters(col):
if col.endswith(("01", "02", "03")):
final_col = col[:4] + "q1"
elif col.endswith(("04", "05", "06")):
final_col = col[:4] + "q2"
elif col.endswith(("07", "08", "09")):
final_col = col[:4] + "q3"
else:
final_col = col[:4] + "q4"
return final_col
df = df.groupby(quarters, axis = 1).mean()
ChkVlu = df.loc['index1'].loc['index2'].loc['requiredcolumn']
type(ChkVlu)
floatovernp.float64?df = df.astype(np.float)