gpt4 book ai didi

python - 在 Jupyter Notebook 上的 Pandas Dataframe 中显示多个空格的方法

转载 作者:行者123 更新时间:2023-12-04 15:25:46 26 4
gpt4 key购买 nike

在笔记本上显示 Pandas Dataframe 对象时,多个空格显示为单个空格。而且我不能复制多个空格。

我想按原样显示所有空格并复制其中的字符串。

有什么办法吗?

display(pd.DataFrame([["ab c", "ab  c"], ["ab   c", "ab    c"]]))

实际

    0     1   
0 ab c ab c
1 ab c ab c

我的期望

    0       1     
0 ab c ab c
1 ab c ab c

最佳答案

这个问题已经在不同的上下文中得到了回答:

keep the extra whitespaces in display of pandas dataframe in jupyter notebook

def print_df(df):
return df.style.set_properties(**{'white-space': 'pre'})

print_df(df)

关于python - 在 Jupyter Notebook 上的 Pandas Dataframe 中显示多个空格的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62283545/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com