代码拉取完成,页面将自动刷新
## Imports
import pandas as pd
from tabulate import tabulate
from datetime import datetime
## Read Data
df = pd.read_excel("data_sources.xlsx")
## Format Cells
newline_replace = lambda x: x.replace("\n","<br/>") if not isinstance(x, float) else x
strip_space = lambda x: x.strip() if not isinstance(x, float) else x
columns_to_format = ["Paper",
"Authors",
"Platform",
"Target Outcomes",
"Labeling Methodology",
"Size",
"Availability",
"Additional Comments",
"Dataset Link (if any)",
"Reference Link"]
for col in columns_to_format:
df[col] = df[col].map(newline_replace)
df[col] = df[col].map(strip_space)
## Link in Title
title_formatter = lambda row: "[{}]({})".format(row["Paper"], row["Reference Link"])
df["Paper"] = df.apply(title_formatter, axis = 1)
## Subset Columns
col_subset = ["Paper",
"Authors",
"Platform",
"Year",
"Target Outcomes"]
df = df[col_subset].copy()
## Sort by Date
df = df.sort_values("Year", ascending=False)
df = df.reset_index(drop=True)
## Generate Markdown Table
md_table = tabulate(df, tablefmt="pipe", headers="keys", showindex="never")
## Output
md_output = """
# Mental Health Datasets
The information below is an evolving list of data sets (primarily from electronic/social media) that have been used to model mental-health phenomena. The raw data (with additional columns) can be found in `data_sources.xlsx`. If you are an author of any of these papers and feel that anything is misrepresented, please do not hesitate to reach out to me at kharrigian@jhu.edu.
**Last Update**: {}
{}
""".format(datetime.now().isoformat(), md_table)
## Write Out
with open("README.md", "w") as the_file:
the_file.write(md_output)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。