本文整理汇总了Python中pytablewriter.MarkdownTableWriter方法的典型用法代码示例。如果您正苦于以下问题:Python pytablewriter.MarkdownTableWriter方法的具体用法?Python pytablewriter.MarkdownTableWriter怎么用?Python pytablewriter.MarkdownTableWriter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pytablewriter
的用法示例。
在下文中一共展示了pytablewriter.MarkdownTableWriter方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: entity_table
# 需要导入模块: import pytablewriter [as 别名]
# 或者: from pytablewriter import MarkdownTableWriter [as 别名]
def entity_table():
writer = MarkdownTableWriter()
writer.table_name = "Entity Cross-Validation Results (5 folds)"
with open("results/DIETClassifier_report.json", "r") as f:
data = json.loads(f.read())
cols = ["support", "f1-score", "precision", "recall"]
writer.headers = ["entity"] + cols
classes = list(data.keys())
classes.sort(key=lambda x: data[x]["support"], reverse=True)
def format_cell(data, c, k):
if not data[c].get(k):
return "N/A"
else:
return data[c][k]
writer.value_matrix = [
[c] + [format_cell(data, c, k) for k in cols] for c in classes
]
return writer.dumps()
示例2: main
# 需要导入模块: import pytablewriter [as 别名]
# 或者: from pytablewriter import MarkdownTableWriter [as 别名]
def main():
with open(filename, "w", encoding="utf8") as f:
f.write(
dedent(
"""\
"i","f","c","if","ifc","bool","inf","nan","mix_num","time"
1,1.10,"aa",1.0,"1",True,Infinity,NaN,1,"2017-01-01 00:00:00+09:00"
2,2.20,"bbb",2.2,"2.2",False,Infinity,NaN,Infinity,"2017-01-02 03:04:05+09:00"
3,3.33,"cccc",-3.0,"ccc",True,Infinity,NaN,NaN,"2017-01-01 00:00:00+09:00"
"""
)
)
writer = pytablewriter.MarkdownTableWriter()
writer.from_csv(filename)
writer.write_table()
示例3: main
# 需要导入模块: import pytablewriter [as 别名]
# 或者: from pytablewriter import MarkdownTableWriter [as 别名]
def main():
df = pd.read_csv(
io.StringIO(
dedent(
"""\
"i","f","c","if","ifc","bool","inf","nan","mix_num","time"
1,1.10,"aa",1.0,"1",True,Infinity,NaN,1,"2017-01-01 00:00:00+09:00"
22,2.20,"bbb",2.2,"2.2",False,Infinity,NaN,Infinity,"2017-01-02 03:04:05+09:00"
333,3.33,"cccc",-3.0,"ccc",True,Infinity,NaN,NaN,"2017-01-01 00:00:00+09:00"
"""
)
),
sep=",",
)
writer = pytablewriter.MarkdownTableWriter()
writer.from_dataframe(df)
writer.write_table()
示例4: intent_table
# 需要导入模块: import pytablewriter [as 别名]
# 或者: from pytablewriter import MarkdownTableWriter [as 别名]
def intent_table():
writer = MarkdownTableWriter()
writer.table_name = "Intent Cross-Validation Results (5 folds)"
with open('results/intent_report.json', 'r') as f:
data = json.loads(f.read())
cols = ["support", "f1-score", "confused_with"]
writer.headers = ["class"] + cols
classes = list(data.keys())
classes.remove('accuracy')
classes.sort(key = lambda x: data[x]['support'], reverse=True)
def format_cell(data, c, k):
if not data[c].get(k):
return "N/A"
if k == "confused_with":
return ", ".join([f"{k}({v})" for k,v in data[c][k].items()])
else:
return data[c][k]
writer.value_matrix = [
[c] + [format_cell(data, c, k) for k in cols]
for c in classes
]
return writer.dumps()
示例5: entity_table
# 需要导入模块: import pytablewriter [as 别名]
# 或者: from pytablewriter import MarkdownTableWriter [as 别名]
def entity_table():
writer = MarkdownTableWriter()
writer.table_name = "Entity Cross-Validation Results (5 folds)"
with open('results/DIETClassifier_report.json', 'r') as f:
data = json.loads(f.read())
cols = ["support", "f1-score", "precision", "recall"]
writer.headers = ["entity"] + cols
classes = list(data.keys())
classes.sort(key = lambda x: data[x]['support'], reverse=True)
def format_cell(data, c, k):
if not data[c].get(k):
return "N/A"
else:
return data[c][k]
writer.value_matrix = [
[c] + [format_cell(data, c, k) for k in cols]
for c in classes
]
return writer.dumps()
示例6: intent_table
# 需要导入模块: import pytablewriter [as 别名]
# 或者: from pytablewriter import MarkdownTableWriter [as 别名]
def intent_table():
writer = MarkdownTableWriter()
writer.table_name = "Intent Cross-Validation Results (3 folds)"
with open("results/intent_report.json", "r") as f:
data = json.loads(f.read())
cols = ["support", "f1-score", "confused_with"]
writer.headers = ["class"] + cols
classes = list(data.keys())
try:
classes.remove("accuracy")
except:
pass
classes.sort(key=lambda x: data[x]["support"], reverse=True)
def format_cell(data, c, k):
if not data[c].get(k):
return "N/A"
if k == "confused_with":
return ", ".join([f"{k}({v})" for k, v in data[c][k].items()])
else:
return data[c][k]
writer.value_matrix = [
[c] + [format_cell(data, c, k) for k in cols] for c in classes
]
return writer.dumps()
示例7: main
# 需要导入模块: import pytablewriter [as 别名]
# 或者: from pytablewriter import MarkdownTableWriter [as 别名]
def main():
writer = ptw.MarkdownTableWriter()
writer.table_name = "zone"
writer.headers = ["zone_id", "country_code", "zone_name"]
writer.value_matrix = [
["1", "AD", "Europe/Andorra"],
["2", "AE", "Asia/Dubai"],
["3", "AF", "Asia/Kabul"],
["4", "AG", "America/Antigua"],
["5", "AI", "America/Anguilla"],
]
# writer instance writes a table to stdout by default
writer.write_table()
writer.write_null_line()
# change the stream to a string buffer to get the output as a string
# you can also get tabular text by using dumps method
writer.stream = io.StringIO()
writer.write_table()
print(writer.stream.getvalue())
# change the output stream to a file
with open("sample.md", "w") as f:
writer.stream = f
writer.write_table()
示例8: print
# 需要导入模块: import pytablewriter [as 别名]
# 或者: from pytablewriter import MarkdownTableWriter [as 别名]
def print(self):
writer = MarkdownTableWriter()
writer.headers = self._make_headers()
writer.value_matrix = self._make_value_matrix()
writer.styles = [Style(align="left")] + [Style(align="center") for _ in range(len(writer.headers) - 1)]
writer.write_table()
print("\n" + self._make_versions_text())
示例9: output
# 需要导入模块: import pytablewriter [as 别名]
# 或者: from pytablewriter import MarkdownTableWriter [as 别名]
def output(tensorboard_dir, output_dir, metrics_keys, steps, output_file_base="metrics"):
"""Output csv and markdown file which accumulated tensorflow event by step and metrics_keys."""
subdirs = GetLogdirSubdirectories(tensorboard_dir)
event_accumulators = []
for subdir in subdirs:
event_accumulator = EventAccumulator(subdir)
# init event accumulator
event_accumulator.Reload()
event_accumulators.append(event_accumulator)
if not metrics_keys:
metrics_keys = {
metrics_key
for event_accumulator in event_accumulators
for metrics_key in _get_metrics_keys(event_accumulator)
}
columns = [_column_name(event_accumulator, metrics_key)
for event_accumulator, metrics_key in itertools.product(event_accumulators, metrics_keys)]
columns.sort()
df = pd.DataFrame([], columns=columns)
for event_accumulator in event_accumulators:
for metrics_key in metrics_keys:
value_step_list = _value_step_list(event_accumulator, metrics_key)
for value, step in value_step_list:
column_name = _column_name(event_accumulator, metrics_key)
df.loc[step, column_name] = value
if steps:
df = df[steps, :]
df = df.sort_index(ascending=False)
# index to column. and re-order column.
df["step"] = df.index
df = df[["step"] + columns]
output_csv = os.path.join(output_dir, "{}.csv".format(output_file_base))
df.to_csv(output_csv, index=False)
output_md = os.path.join(output_dir, "{}.md".format(output_file_base))
writer = pytablewriter.MarkdownTableWriter()
writer.char_left_side_row = "|" # fix for github
writer.from_dataframe(df)
with open(output_md, "w") as file_stream:
writer.stream = file_stream
writer.write_table()
message = """
output success
output csv: {}
output md: {}
""".format(output_csv, output_md)
print(message)