-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsv_to_markdown_table.py
32 lines (27 loc) · 1.01 KB
/
csv_to_markdown_table.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 18 16:54:21 2019
@author: pieterhuy
"""
import pandas as pd
import numpy as np
# Read the source data
df = pd.read_csv('Abbreviations_and_Acronyms.csv', quotechar='"')
# get the domain name from the links
## function to format the reference link into markdown links
def format_reference(link):
if str(link) != "nan":
return "[reference]"+"("+str(link)+")"
## apply function
df["Reference_Link"] = list(map(format_reference, df["Reference_Link"]))
# sort values
df = df.sort_values('Abbreviation')
# append a numpy array with n times the header seperator, with n being the
# number of columns then store this array as a pandas dataframe with setting the
# header to the original header
df = pd.DataFrame(
np.insert(df.values, 0, values=['---'] * len(df.columns), axis=0),
columns=df.columns)
# write this to a markdown file using the csv parser and setting the seperator
# to pipes, we do not care about the index
df.to_csv('README.md', sep='|', index=False)