简体   繁体   English

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

[英]Way to show multiple spaces in Pandas Dataframe on Jupyter Notebook

When displaying Pandas Dataframe object on notebook, multiple spaces are shown as single space.在笔记本电脑上显示 Pandas Dataframe object 时,多个空格显示为单个空格。 And I cannot copy multiple spaces.而且我不能复制多个空格。

I would like to show all spaces as they are and copy a string of them.我想按原样显示所有空格并复制它们的字符串。

Any way to do so?有什么办法吗?

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

Actual实际的

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

My expectation我的期望

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

This issue has been answered in a different context:这个问题已经在不同的背景下得到了回答:

keep the extra whitespaces in display of pandas dataframe in jupyter notebook 在 jupyter 笔记本中保留额外的空格显示 pandas dataframe

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

print_df(df)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM