I have an excel sheet and have huge data in many columns and I need to print those columns to follow each other in one column in a text file .. I searched a lot for a tool to do this but couldn’t find and tried to take it manually but I’m stuck in the data. Can this be done by python?
i have data like this in excel
JavaScript
x
12
12
1
1760 -67.4144 -51.5741
2
1761 -70.0035 -52.6686
3
1762 -82.4125 -33.0582
4
1763 -88.4259 -35.5613
5
1764 -63.6835 -38.474
6
1765 -90.6215 -43.0932
7
1766 -65.9159 -38.9343
8
1767 -76.7137 -42.3622
9
1768 -94.9792 -31.1532
10
1769 -71.3852 -46.629
11
1770 -65.8548 -47.4222
12
and need to write them in text file like this
JavaScript
1
34
34
1
1760
2
1761
3
1762
4
1763
5
1764
6
1765
7
1766
8
1767
9
1768
10
1769
11
1770
12
-67.4144
13
-70.0035
14
-82.4125
15
-88.4259
16
-63.6835
17
-90.6215
18
-65.9159
19
-76.7137
20
-94.9792
21
-71.3852
22
-65.8548
23
-51.5741
24
-52.6686
25
-33.0582
26
-35.5613
27
-38.474
28
-43.0932
29
-38.9343
30
-42.3622
31
-31.1532
32
-46.629
33
-47.4222
34
Advertisement
Answer
First run this command in terminal
JavaScript
1
4
1
pip install pandas
2
pip install openpyxl
3
pip install xlrd
4
Then run this in python
JavaScript
1
11
11
1
import pandas as pd
2
3
df = pd.read_excel('my_file.xlsx')
4
5
my_file = open('my_file.txt','w')
6
for data in df.columns:
7
my_file.write(df[data].to_string(index=False)+'n')
8
9
my_file.close()
10
11
To remove empty Nan values from seies, use dropna
JavaScript
1
3
1
my_file.write(df[data].dropna().to_string(index=False)+'n')
2
3