我有一個帶有字符串列和浮點數列的pandas DataFrame我想用drop_duplicates
刪除重複項。有些重複的部分並不完全一樣,因爲在小數位低位有一些細微差別。如何刪除重複精度較低的重複項?刪除重複精度較低
例子:
import pandas as pd
df = pd.DataFrame.from_dict({'text': ['aaa','aaa','aaa','bb'], 'result': [1.000001,1.000000,2,2]})
df
result text
0 1.000001 aaa
1 1.000000 aaa
2 2.000000 aaa
3 2.000000 bb
我想獲得
df_out = pd.DataFrame.from_dict({'text': ['aaa','aaa','bb'], 'result': [1.000001,2,2]})
df_out
result text
0 1.000001 aaa
1 2.000000 aaa
2 2.000000 bb
Binning是一個針對此問題的過於複雜的解決方案,但我仍然會共享一個鏈接:https://chrisalbon.com/python/pandas_binning_data.html –