By executing the following function, it can be output in tabular format for Markdown.
def df_table(df):
for col in df.columns:
print('|', col, end="", sep='')
print('|')
for col in df.columns:
print('| ---- ', end="", sep='')
print('|')
for row in range(len(df)):
print('|', end="")
for col in range(df.shape[1]):
print(df.iat[row,col],'|', end="", sep='')
print()
| sepal length (cm) | sepal width (cm) | petal length (cm) | petal width (cm) | target |
| ---- | ---- | ---- | ---- | ---- |
| 5.1 | 3.5 | 1.4 | 0.2 | setosa |
| 4.9 | 3.0 | 1.4 | 0.2 | setosa |
| 4.7 | 3.2 | 1.3 | 0.2 | setosa |
| 4.6 | 3.1 | 1.5 | 0.2 | setosa |
| 5.0 | 3.6 | 1.4 | 0.2 | setosa |
If you copy and paste it and output it to a Markdown file, It can be displayed as a table as shown below.
sepal length (cm) | sepal width (cm) | petal length (cm) | petal width (cm) | target |
---|---|---|---|---|
5.1 | 3.5 | 1.4 | 0.2 | setosa |
4.9 | 3.0 | 1.4 | 0.2 | setosa |
4.7 | 3.2 | 1.3 | 0.2 | setosa |
4.6 | 3.1 | 1.5 | 0.2 | setosa |
5.0 | 3.6 | 1.4 | 0.2 | setosa |
Recommended Posts