Skip to content
This repository has been archived by the owner on Dec 10, 2019. It is now read-only.

Commit

Permalink
Create CSV 2 JSON or HTML Table
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbailey committed Sep 16, 2015
1 parent 13628c1 commit d281965
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions CSV 2 JSON or HTML Table
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import pandas
import json

df = pandas.read_csv('file.csv', encoding='utf-8-sig')

headers = map(lambda x: x, df.columns)
output = {'headers': headers}
output.update({'values': json.loads(df.to_json(orient='records'))})
#print json.dumps(output)


### /\ JSON
### \/ HTML

print "<html>"
print """
<style>
table, th , td {
border: 1px solid grey;
border-collapse: collapse;
padding: 5px;
}
table tr:nth-child(odd) {
background-color: #f1f1f1;
}
table tr:nth-child(even) {
background-color: #ffffff;
}
</style>
"""

print "<table><tr>"
for x in headers:
print "<td>", x, "</td>"

print "</tr>"
for x in df.iterrows():
print "<tr>"
for y in x[1]:
print "<td>", y, "</td>"
print "</tr>"

print "</table></html>"

0 comments on commit d281965

Please sign in to comment.