-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathconvert_csv_to_md.py
More file actions
30 lines (23 loc) · 997 Bytes
/
convert_csv_to_md.py
File metadata and controls
30 lines (23 loc) · 997 Bytes
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
import os
import pandas as pd
def csv_to_markdown(csv_file, md_file):
# Load the CSV file into a DataFrame
df = pd.read_csv(csv_file)
# Replace NaN values with a space
df = df.fillna(' ')
# Convert the DataFrame to a Markdown table
md_table = df.to_markdown(index=False)
# Ensure the directory for the output file exists
os.makedirs(os.path.dirname(md_file), exist_ok=True)
# Write the Markdown table to a file
with open(md_file, 'w', encoding="utf-8") as f:
f.write(md_table)
if __name__ == "__main__":
csv_file = 'implementations/compatibility_hardware.csv'
md_file = 'implementations/_compatibility_hardware.md'
csv_to_markdown(csv_file, md_file)
print(f"Markdown table has been written to {md_file}")
csv_file = 'implementations/compatibility_software.csv'
md_file = 'implementations/_compatibility_software.md'
csv_to_markdown(csv_file, md_file)
print(f"Markdown table has been written to {md_file}")