2020年12月25日星期五

df.quantile(axis = 1) throws NaN

I have a dataframe df with 70 columns. I am trying to calculate quantiles using df.quantile() function along axis = 1. Here are the details of the dataframe.

> print(df.head(4))

ts                                                                              2020-11-01 01:00:00       12.3708       11.7133       12.2125       12.3325     2020-11-01 01:10:00       12.6442       12.1883       12.5625       12.3233     2020-11-01 01:20:00       12.8042       11.7109       11.8765       12.1134     2020-11-01 01:30:00       12.3176       10.6824       11.8361       11.5672                                 WS_656         WS_657       WS_664        WS_659  \  ts                                                                              2020-11-01 01:00:00       12.0217       11.6233       12.6108       12.2458     2020-11-01 01:10:00       13.0342       12.5917       12.5225       11.7658     2020-11-01 01:20:00       11.6042       10.6496       11.8874       12.3613     2020-11-01 01:30:00       11.3118       9.98403          10.6       10.5992                                 WS_663         WS_666  ...       WS_715  \  ts                                               ...                   2020-11-01 01:00:00       15.3058       15.1433  ...       12.9008     2020-11-01 01:10:00       15.3283       15.0625  ...       12.6042     2020-11-01 01:20:00       15.3765        15.058  ...       11.7462     2020-11-01 01:30:00       14.7689       14.4992  ...       11.0294                                  WS_703       WS_702        WS_723        WS_724  \  ts                                                                              2020-11-01 01:00:00        10.985       12.4608       14.3942       11.3125     2020-11-01 01:10:00       11.7508         13.43       14.5042        10.785     2020-11-01 01:20:00       11.0941       13.2546       14.8983       9.91513     2020-11-01 01:30:00       8.98067       10.4874       14.8546       9.90168                                  WS_725       WS_726        WS_728        WS_727  \  ts                                                                              2020-11-01 01:00:00          13.5       15.0367       12.8908         15.08     2020-11-01 01:10:00       13.8575       15.2733       13.7633       15.0725     2020-11-01 01:20:00       13.6412       15.1655       12.7546       15.1882     2020-11-01 01:30:00       13.4588       14.4403       12.8252       14.1966                                  WS_718    ts                                   2020-11-01 01:00:00        14.795    2020-11-01 01:10:00       14.6083    2020-11-01 01:20:00       14.4706    2020-11-01 01:30:00       13.6345      [4 rows x 70 columns]  
> q10 = df.quantile(0.1, axis = 1)  > print(q10)  
ts  2020-11-01 01:00:00   NaN  2020-11-01 01:10:00   NaN  2020-11-01 01:20:00   NaN  2020-11-01 01:30:00   NaN  2020-11-01 01:40:00   NaN                         ..  2020-12-01 00:00:00   NaN  2020-12-01 00:10:00   NaN  2020-12-01 00:20:00   NaN  2020-12-01 00:30:00   NaN  2020-12-01 00:40:00   NaN  Name: 0.1, Length: 4319, dtype: float64  

However, if I loop through as:

> q10 = list()    > for k in range(len(df)):         q10.append(df.iloc[k,:].quantile(0.1))    > print(q10)  

It prints a list of size len(df) with correct quantile values corresponding to each row. so want to understand why this works when I operate row-wise on the same df, but does not work on the entire dataframe.

https://stackoverflow.com/questions/65453348/df-quantileaxis-1-throws-nan December 26, 2020 at 11:05AM

没有评论:

发表评论