我正在尝试创建一个数据框,其中有一列包含一串带有线条的文本。这些行由行分隔,以便于阅读。
string=['''
hello all:. I request the following from you:
do the laundry:
sleep early
wake up early
feed the chicken
''']
ii=pd.DataFrame(string, columns=['requirement'])
ii
但是,当我生成数据框时,表格显示非常混乱,所有新行都由 ( ) 文本格式。
大家好:。我向您提出以下要求: 洗衣服: 早点睡 起得很早 喂鸡
如何保留 PD Dataframe 中的行以便于阅读?
一种快速简便的方法可能是取消换行:
print(ii.to_string().replace('\\n', '\n'))
输出:
requirement
0
hello all:. I request the following from you:
do the laundry:
sleep early
wake up early
feed the chicken
你可以使用:
ii['requirement'].replace('\n', '', regex=True, inplace=True)