Skip to content

Instantly share code, notes, and snippets.

@t27
Created May 25, 2015 04:45
Show Gist options
  • Save t27/5f1c2127e75bdae6ca8e to your computer and use it in GitHub Desktop.
Save t27/5f1c2127e75bdae6ca8e to your computer and use it in GitHub Desktop.
A python script to convert a spreadsheet(in CSV format) to a question-answer type document(where the heading of each column is the question and each row is an answer), generally useful to generate readable documents from surveys or similar spread sheets
#a script to convert a spreadsheet to a question-answer type document(where the heading of each column is the question and each row is an answer), generally useful to generate readable documents from surveys or similar spread sheets
import csv
with open('survey.csv', 'rb') as csvfile:
reader = csv.reader(csvfile)
csv_as_list = list(reader)
titles=csv_as_list[0];
for i in range(1,len(csv_as_list)):
print "==================================================================";
for j in range(len(csv_as_list[i])):
print "\n"+titles[j]+"\n"
if(csv_as_list[i][j].strip()==""):
print "NA\n"
else:
print csv_as_list[i][j]+"\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment