I have a long list of DMS values that look like below.
lst = ['9', '22', '26.9868', 'N',
'118', '23', '48.876', 'E',
'9', '22', '18.6132', 'N',
'118', '23', '5.2188', 'E',
'9', '19', '41.4804', 'N',
'118', '19', '23.1852', 'E']
I want to write this data as a csv file in the following format:
>Solution :
You can use numpy and pandas:
lst = ['9', '22', '26.9868', 'N',
'118', '23', '48.876', 'E',
'9', '22', '18.6132', 'N',
'118', '23', '5.2188', 'E',
'9', '19', '41.4804', 'N',
'118', '19', '23.1852', 'E']
import numpy as np
import pandas as pd
(pd.DataFrame(np.array(lst).reshape(-1,4),
columns=['deg', 'min', 'sec', 'direction'])
.to_csv('filename.csv', index=False)
)
Output file (as text):
deg,min,sec,direction
9,22,26.9868,N
118,23,48.876,E
9,22,18.6132,N
118,23,5.2188,E
9,19,41.4804,N
118,19,23.1852,E
