Reputation: 1
I have xlsx file estimated 20000 rows and 2 columns for example ;
station feedback
1 aax2a3x9564
1 a52a42x366x
1 29a9a756022
1 a6645207742
2 a7692202650
2 a64399x05a6
2 a9909a2x470
2 32654440a54
4 a9306aa7244
4 2a9a303342x
4 a66a52054xx
9 424272a64x0
9 aa4733a3a60
10 4225034a090
10 a9a29054x32
i want to use the first column (station) as Txt File names and second column (feedback) as data?
How can i achieve this?
Upvotes: 0
Views: 147
Reputation: 120479
You can use pandas
and openpyxl
to do that with no pain:
# Python env: pip install pandas openpyxl
# Anaconda env: conda install pandas openpyxl
import pandas as pd
df = pd.read_excel('data.xlsx')
for station, data in df.groupby('station'):
with open(f'{station}.txt', 'w') as fp:
fp.writelines('\n'.join(data['feedback'].tolist()))
Content of 1.txt
:
aax2a3x9564
a52a42x366x
29a9a756022
a6645207742
Content of 2.txt
:
a7692202650
a64399x05a6
a9909a2x470
32654440a54
Upvotes: 1