Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
パンダの時系列内で使用される数値の小数点以下の桁数を見積もるにはどうすればよいですか?
例えば
x=[1.01,1.01,1.03]
私はしたいです
in[0]: estimate_decimal_places(x) out[0] : 2
x=[1.1,1.5,2.0]
in[0]: estimate_decimal_places(x) out[0] : 1
本当に醜いですが、機能し、マークが指摘したコーナーケースをカバーする必要があります
def decimal_places(num): return max(len(('%.15f'%num).strip("0").split('.')[1]),0)
編集:
とにかく、これはのようなもので失敗しますdecimal_places(90.34)。私のマシンでは、印刷すると90.340000000000003に変換され、これが間違った結果になります。
decimal_places(90.34)
押し込みすぎない限り、うまく機能12し15ます12。
12
15