I\'m trying to modify a csv that is uploaded into my flask application. I have the logic that works just fine when I don\'t upload it through flask.
import p
FileStorage
is a file-like wrapper around the incoming data. You can pass it directly to read_csv
.
pd.read_csv(request.files['data_file'])
You most likely should not be performing those replace
calls on the data, as the CSV module should handle that and the naive replacement can corrupt data in quoted columns. However, if you still need to, you can read the data out just like you were before.
data = request.files['data_file'].read()
If your data has a mix of quoting styles, you should fix the source of your data.
Answering my own question in case someone else needs this.
FileStorage objects have a .stream attribute which will be an io.BytesIO
f = request.files['data_file']
df = pandas.read_csv(f.stream)