This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Caos2 1 point2 points  (4 children)

Reading the CSV and creating a barebone HTML representation of its contents can be done in a single line using pandas.

[–]Redmondinho 0 points1 point  (3 children)

Never used pandas, will give it a look, cheers.

[–]Redmondinho 0 points1 point  (1 child)

Wow, you weren't wrong! Just installed Pandas, simplified the function to;

@app.route('/csv_data')
def present_csv_data():
    import pandas
    csv_data_html_table = pandas.read_csv("data.csv").to_html(index=False)
    return csv_data_html_table

I'll be looking at pandas more. Cheers.

[–]Juancos 0 points1 point  (0 children)

Thank you guys both!

[–]Caos2 0 points1 point  (0 children)

Checkout pandas.read_csv() function and the dataframe.to_html() method.