I have found the dataset:
I want to transform it in order to appear exactly like:
My main problem is how to put the row header as values in a column named years. Any thoughts or any ideas?
I have found the dataset:
I want to transform it in order to appear exactly like:
My main problem is how to put the row header as values in a column named years. Any thoughts or any ideas?
I am going to assume that your dataset, is a CSV file, I would do the following:
import csv
from operator import itemgetter
with open('name.csv', 'key') as f:
data = [line for line in csv.reader(f)]
newRecord = [Entity, Code, Year, Prevelance of Obesity]
data.append(newRecord)
data.sort(key=itemgetter(1)) # 1 being the column number
with open('name.csv', 'w') as f:
csv.writer(f).writerows(data)