Python 提升、支撑和信心四舍五入至4位小数,但提升变为1位小数

Python 提升、支撑和信心四舍五入至4位小数,但提升变为1位小数,python,pandas,numpy,Python,Pandas,Numpy,我使用Apyori API从数据集生成关联 #categorize central region into a basket basket = (df .groupby(['Customer Name', 'Sub-Category'])['Quantity'] .sum().unstack().reset_index().fillna(0) .set_index('Customer Name')) #create a function t

我使用Apyori API从数据集生成关联

#categorize central region into a basket
basket = (df
         .groupby(['Customer Name', 'Sub-Category'])['Quantity']
         .sum().unstack().reset_index().fillna(0)
         .set_index('Customer Name'))

#create a function to normalize the data
#any >1 values will return 1, any <1 values will return 0
def encode_units(x):
    if x <= 0:
        return 0
    if x>=1:
        return 1

#apply the function to basket
basket_sets = basket.applymap(encode_units)
basket_sets
#find frequent itemset, which minimum support is at least 0.35
frequent_itemsets = apriori(basket_sets, min_support=0.35, use_colnames=True)

#generate rules with corresponding support, lift and confidence
rules = association_rules(frequent_itemsets, metric="lift", min_threshold=1)

a = rules[(rules['lift'] >= 1) & (rules['confidence'] >= 0.8)]
t = a.sort_values(['lift', 'confidence'], ascending=False)[['antecedents', 'consequents', 'lift', 'support', 'confidence']]
我应该如何将提升、支持和信心四舍五入到小数点后4位,并将先行项的索引放在后面显示?谢谢

==================================更新====================

我使用
t.index=np.arange(1,len(t)+1)
来替换索引,但四舍五入我仍在寻找解决方案

===============================更新2====================

好的,我已经通过使用找到了答案

t.lift=t.lift.apply(np.round,小数=4)
t、 支持度=t.support.apply(np.round,小数=4)

t、 confidence=t.confidence.apply(np.round,decimals=4)

好的,要回答我自己的问题,我实际上通过使用

t.lift=t.lift.apply(np.round,小数=4)
t、 支持度=t.support.apply(np.round,小数=4)
t、 置信度=t.置信度.应用(np.四舍五入,小数=4

    antecedents           consequents   lift    support confidence
74  (Accessories, Storage)  (Paper) 1.114737    0.353090    0.858896
166 (Storage, Furnishings)  (Paper) 1.106141    0.378310    0.852273
170 (Phones, Storage)   (Paper) 1.103379    0.372005    0.850144
146 (Binders, Storage)  (Paper) 1.094049    0.460277    0.842956
etc...