Generate Markdown Table

Iterates over the saved data from the ETL routine, selecting the following columns: 'Employer', 'Lang', 'Date', 'Shortest Sentence', 'Longest Sentence', 'Words', 'Readability Consensus'. These are then saved as a table, in Markdown format, in 'table.md'.

In [1]:
# Data handling, structures and analysis tools, SQLite database interface
import pandas as pd
import sqlite3

# Default options
x_variable = 'modification_date'
In [2]:
# Read database, attach as Pandas dataframe sorted by date
db = sqlite3.connect("Data/Applications.db")
columns = 'Title, Readability, Words, Sentences, Interview, Offer, Reply, modification_date'
df = pd.read_sql_query('SELECT ' + columns + ' FROM applications ORDER BY Date(' + x_variable + ') DESC', db)
db.close()

# Cast `modification_date` as DateTime, then drop `modification_date`-column
df['Date'] = pd.to_datetime(df['modification_date'], unit='s')
df = df.drop('modification_date', 1)

df.head()
Out[2]:
Title Readability Words Sentences Interview Offer Reply Date
0 123lyd 9th and 10th grade 177.0 12.0 0 0 0 2016-11-13 21:07:28
1 Academic Work 11th and 12th grade 221.0 13.0 0 0 0 2016-11-13 21:07:28
2 Academic Work, Dokumenthåndtering 11th and 12th grade 242.0 15.0 0 0 0 2016-11-13 21:07:28
3 AcademicMinds 12th and 13th grade 241.0 11.0 0 0 0 2016-11-13 21:07:28
4 Adecco 11th and 12th grade 146.0 8.0 0 0 0 2016-11-13 21:07:28
In [3]:
# Parse Dataframe and apply Markdown
cols = df.columns
df2 = pd.DataFrame([['---','---','---','---','---','---','---','---']], columns=cols)
df3 = pd.concat([df2, df])

# Save table to .md-file
try:
    df3.to_csv('Data/table.md', sep="|", index=False)
    pass
except IOError as e:
    print (e)
    pass
finally:
    print ('Saved Data/table.md.')
Saved Data/table.md.