There is problem some column is not numeric.You can check dtypes:print (t_unit.dtypes)B18_LR_T float64B18_B1_T float64ext_T objectdtype: object然后先尝试通过 astype转换为数字:Then try convert to numeric first by astype:t_unit.ext_T = t_unit.ext_T.astype(float)如果:然后将 to_numeric 与参数errors='coerce'用于将错误数据转换为NaN:then use to_numeric with parameter errors='coerce' for convert bad data to NaN:t_unit.ext_T = pd.to_numeric(t_unit.ext_T, errors='coerce')所有代码:#simulate string columnt_unit.ext_T = t_unit.ext_T.astype(str)print (t_unit.dtypes)B18_LR_T float64B18_B1_T float64ext_T objectdtype: object#convert to floatt_unit.ext_T = t_unit.ext_T.astype(float)print (t_unit)L = []for key in t_unit.columns: ts_wk = t_unit[key].resample('W-MON') #remove inplace=True ts_wk_05p = ts_wk.apply(lambda x: x.quantile(0.05)).round(decimals=1).rename(key+'_05p') ts_wk_95p = ts_wk.apply(lambda x: x.quantile(0.95)).round(decimals=1).rename(key+'_95p') L.append(ts_wk_05p) L.append(ts_wk_95p)print (pd.concat(L, axis=1)) B18_LR_T_05p B18_LR_T_95p B18_B1_T_05p B18_B1_T_95p ext_T_05p \datetime 2016-03-28 20.2 26.8 20.1 24.8 7.0 ext_T_95p datetime 2016-03-28 9.8 这篇关于TypeError:无法将序列乘以'float'类型的非整数(python 2.7)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-15 11:10