我想将数据框保存到txt文件中 #创建时间表的数据框
import pandas as pd
timeline_table = pd.DataFrame.from_dict(timeline, orient = 'index', columns = ['events'])
a = timeline_table.reset_index()
r=a.rename(columns={"index": "years"})
final_table = r.shift()[1:]
print(final_table)
#将时间表/时间表保存到新文件中
path= "data.txt"
with open(path, mode = 'w') as output:
output.write(f'{final_table}')
输出如下:
1 1000 About thirty countries maintain about seventy ...
2 1270 from which derived the Old French pole antarti...
3 1391 from which derived the Old French pole antarti...
4 1773 European maps continued to show this hypotheti...
5 1775 European maps continued to show this hypotheti...
.. ... ...
57 2014 In 1985, three British scientists working on d...
58 2015 With the ban of CFCs in the Montreal Protocol ...
59 2018 which operated its own scientific station—Worl...
我希望包含与提取的年份相对应的句子的所有行都完全显示在输出文件中。 有什么办法吗?
答案 0 :(得分:0)
pd.set_option('display.max_colwidth',-1)