我正在学习一个关于市场篮子分析的教程。 所有的工作都很好,但我想将数据导出到只有文本和数字的csv
csv的输出如下所示
,antecedents,consequents,antecedent support,consequent support,support,confidence,lift,leverage,conviction
0,frozenset({'DOLLY GIRL LUNCH BOX'}),frozenset({'SPACEBOY LUNCH BOX'}),0.22,0.28,0.21,0.95,3.41,0.148,15.84
1,frozenset({'SPACEBOY LUNCH BOX'}),frozenset({'DOLLY GIRL LUNCH BOX'}),0.28,0.22,0.21,0.75,3.41,0.15,3.12
应该是这样的
antecedents,consequents,antecedent support,consequent support,support,confidence,lift,leverage,conviction
SPACEBOY LUNCH BOX,DOLLY GIRL LUNCH BOX,0.28,0.22,0.21,0.75,3.41,0.15,3.12
DOLLY GIRL LUNCH BOX,SPACEBOY LUNCH BOX,0.22,0.28,0.21,0.96,3.41,0.1484,15.84
我想去掉文本中的frozenset({})
部分
这在我们的熊猫中是可能的吗?我应该用str.strip
解构和重建数据帧吗
df['antecedents'] = df['antecedents'].str.strip('({})')
df['consequents'] = df['consequents'].str.strip('({})')
通过
agg()
尝试:或
通过
str.strip()
分两步进行:或
通过
apply()
:您可以尝试以下方法:
相关问题 更多 >
编程相关推荐