I have copied a table from a webpage and when I paste it to a text file (or excel) the table a list of values. here is the example list.
['1', '42', 'Konya', '40.838', '42', '62', 'Tunceli', '7.582']
I want the 0th item on column 1 1st item on column 2 3th item on column 3 4th item on column 4
Below is a long way of doing it( i assume)
import pandas as pd
mylist=['1', '42', 'Konya', '40.838', '42', '62', 'Tunceli', '7.582']
city=[]
code=[]
area=[]
for i,line in enumerate(mylist):
if i%4==0:
index.append(line)
if i%4==1:
code.append(line)
if i%4==2:
city.append(line)
if i%4==3:
area.append(line)
dict={'code':code,'city':city,'area':area}
df=pd.DataFrame(dict)
What I am looking for is the code above but in a shorter way, I am sure someone has a clever way of doing it, just I cannot find it...