简体   繁体   中英

Why doesn't Pandas round when dtype is float16?

Why does Pandas not round DataFrames when the dypes are np.float16 ?

pd.DataFrame(np.random.rand(10) for x in range(0, 10)).astype(np.float16).round(2)

Or

np.round(pd.DataFrame(np.random.rand(10) for x in range(0, 10)).astype(np.float16), 2)

Or

pd.DataFrame(np.random.rand(10) for x in range(0, 10)).astype(np.float16).round({0:2, 1:2})

This must have come up before but I can't find it anywhere?

It is rounding. Up to the limits of float16 precision, the results are exactly what you asked for. However, the limits of float16 precision are significantly lower than the 6 significant figures Pandas attempts to print by default, so you see some of the representation imprecision that is usually hidden when printing floating-point numbers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM