Dataframe 上传并显示数据帧| AttributeError:';内置函数或方法';对象没有属性';更换';

Dataframe 上传并显示数据帧| AttributeError:';内置函数或方法';对象没有属性';更换';,dataframe,flask,replace,attributeerror,Dataframe,Flask,Replace,Attributeerror,“我正试图通过flask上传和显示一个数据帧,当我想显示它时,”它说 AttributeError: 'builtin_function_or_method' object has no attribute 'replace'. 我在YT上找到了这个代码,我不知道它是否正确。有人能帮我吗 from flask import Flask, render_template, request from werkzeug.utils import secure_filename import pan

“我正试图通过flask上传和显示一个数据帧,当我想显示它时,”它说

AttributeError: 'builtin_function_or_method' object has no attribute 'replace'. 
我在YT上找到了这个代码,我不知道它是否正确。有人能帮我吗

from flask import Flask, render_template, request
from werkzeug.utils import secure_filename
import pandas as pd
import csv

def reencode(file):
    for line in file:
       yield line.decode('windows-1250').encode('utf-8')

@app.route("/data")
def data():
  df = pd.read_csv("Sistema_de_Stock.csv", encoding='latin-1')
  df = df.drop(df.loc['stock al cargar':].columns, axis=1)
  df.to_html('data.html')
  with open("data.html", 'r', encoding='latin-1') as file:
    file = file.read
  **file = file.replace("<table","<table class='rwd-table'")**
  with open("data.html","w") as file_write:
    file_write.write(html + file)
  data = os.startfile("data.html")

  return data
从烧瓶导入烧瓶,呈现模板,请求
从werkzeug.utils导入安全文件名
作为pd进口熊猫
导入csv
def重新编码(文件):
对于文件中的行:
屈服线。解码('windows-1250')。编码('utf-8'))
@应用程序路径(“/data”)
def data():
df=pd.read_csv(“Sistema_de_Stock.csv”,编码='latin-1')
df=df.drop(df.loc['stock al cargar':]列,轴=1)
df.to_html('data.html'))
以open(“data.html”,“r”,encoding='latin-1')作为文件:
file=file.read

**file=file.replace(“
file.read
是一个方法,因此您应该调用该方法。此外,您可能希望重命名该变量,以明确它不是文件处理程序:

with open('data.html', 'r', encoding='latin-1') as file:
    #    call the method ↓
    file_data = file.read().replace('<table', "<table class='rwd-table'")
  with open('data.html', 'w') as file_write:
    file_write.write(html + file_data)
  data = os.startfile('data.html')
以open('data.html','r',encoding='latin-1')作为文件的
:
#调用该方法&downarrow;
file_data=file.read().replace('