Search code examples
pythonpandasparsingxlsx

Parsing and saving the rows of excel file using pandas


Have an excel file with a column with some text in each row of this column.

I'm using pandas pd.read_excel() to open this .xlsx file. Then I would like to do the following: I would like to save every row of this column as a distinct .txt file (that would have the text from this row inside this file). Is it possible to be done via pandas?


Solution

  • the basic idea would be to use an iterator to loop over the rows, opening a each file and writing the value in, something like:

    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)