๐ ๊ณต๋ถํ๋ ์ง์ง์ํ์นด๋ ์ฒ์์ด์ง?
๋ค์ ๋์ .. Flask CSV ๋ถ๋ฌ์์ HTML์ ํ๋ก ์๊ฐํํ๊ธฐ(4) ๋ณธ๋ฌธ
๐ฉ๐ป ๋ฐฑ์๋(Back-End)/Node js
๋ค์ ๋์ .. Flask CSV ๋ถ๋ฌ์์ HTML์ ํ๋ก ์๊ฐํํ๊ธฐ(4)
์ง์ง์ํ์นด 2022. 11. 30. 13:47728x90
๋ฐ์ํ
<๋ณธ ๋ธ๋ก๊ทธ๋ geeksforgeeks ๋์ ๋ธ๋ก๊ทธ๋ฅผ ์ฐธ๊ณ ํด์ ๊ณต๋ถํ๋ฉฐ ์์ฑํ์์ต๋๋ค :-)>
https://www.geeksforgeeks.org/convert-csv-to-html-table-using-python-pandas-and-flask-framework/
Convert CSV to HTML Table using Python Pandas and Flask Framework - GeeksforGeeks
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
www.geeksforgeeks.org
๐ Python Pandas ๋ฐ Flask Framework๋ฅผ ์ฌ์ฉํ์ฌ CSV ํ์ผ์ HTML ํ ์ด๋ธ ๋ก ๋ณํ
๐ต ํ์ผ ๊ตฌ์กฐ
๐ต ์ฝ๋ ๊ตฌํ
- app.py
# importing flask
from flask import Flask, render_template
# importing pandas module
import pandas as pd
# flask ๊ฐ์ฒด๋ฅผ app ์ ํ ๋น
app = Flask(__name__)
# reading the data in the csv file
df = pd.read_csv('test.csv')
df.to_csv('sample_testdata.csv', index=None)
# route to html page - "table"
# ํด๋น ๋ผ์ฐํ
๊ฒฝ๋ก๋ก ์์ฒญ์ด ์์ ๋ ์คํํ ํจ์๋ฅผ ๋ฐ๋ก ๋ฐ์ ์์ฑํจ
@app.route('/')
@app.route('/table')
def table():
# converting csv to html
data = pd.read_csv('test.csv')
return render_template('table.html', tables=[data.to_html()], titles=[''])
# ํ๋ผ์คํฌ ์๋ฒ ๊ตฌ๋ (์๋ฒ๋ก ๊ตฌ๋ํ IP ์ ํฌํธ๋ฅผ ์ต์
์ผ๋ก ๋ฃ์ด์ค)
if __name__ == "__main__":
app.run(host="localhost", port=int("5000"))
- templates/table.html
<!DOCTYPE html>
<html lang="en">
<head>
<title> Table </title>
</head>
<body>
<div align="center">
<table>
<h1>
<!--Displaying the converted table-->
{% for table in tables %}
<h2>{{titles[loop.index]}}</h2>
{{ table|safe }}
{% endfor %}
</h1>
</table>
</div>
</body>
</html>
728x90
๋ฐ์ํ
'๐ฉโ๐ป ๋ฐฑ์๋(Back-End) > Node js' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๋ค์ ๋์ .. Flask POST ์ฌ์ฉํด๋ณด๊ธฐ (7) (0) | 2022.12.01 |
---|---|
๋ค์ ๋์ .. Flask GET ์ฌ์ฉํด๋ณด๊ธฐ (6) (0) | 2022.12.01 |
HTML์์ Python์ ์ฌ์ฉํ ์ ์๋ PyScript (15) (0) | 2022.11.28 |
HTML์์ Python์ ์ฌ์ฉํ ์ ์๋ PyScript (14) (0) | 2022.11.28 |
HTML์์ Python์ ์ฌ์ฉํ ์ ์๋ PyScript (13) (1) | 2022.11.28 |
Comments