使用 pandas 解析并保存 excel 文件的行

Parsing and saving the rows of excel file using pandas

有一个 excel 文件,其中有一列,每一行都有一些文本。

我正在使用 pandas pd.read_excel() 打开这个 .xlsx 文件。然后我想执行以下操作:我想将此列的每一行保存为一个不同的 .txt 文件(该文件中包含此行的文本)。是否可以通过 pandas 完成?

基本思想是使用迭代器遍历行,open每个文件并写入值,例如:

import pandas as pd
df = pd.read_excel('test.xlsx')
for i, value in enumerate(df['column']):
  with open(f'row-{i}.txt', 'w') as fd:
    fd.write(value)