aren
February 6, 2020, 8:48pm
1
Hi, I successfully download my data table as csv file, however there is an ID column which I never added in the data table, why is this happening and what is the possible way to download the csv file that doesn’t contain this column?
Thanks in advance
That is the row ID. You could put your DataTable rows into a Pandas DataFrame and save that to a CSV file. For example:
Hi @ldelfin ,
If you want to construct a Pandas data frame out of data held in your Anvil data tables, I’d suggest you construct a list of dicts with the information you want, and then call DataFrame.from_dict() on it.
Eg, if I have a table called “people”, which has name and age columns, plus group which is a link to a row from the “groups” table, and the “groups” table has a column called name, I could do:
from anvil.tables import app_tables
import pandas
# Get an iterable object with all t…
Once you have your data in a DataFrame, you can download it by making it an Anvil Media object. Explained more here:
You can get to a media object from a DataFrame by serializing the DataFrame.
You can get to a DataFrame from a media object by reading the media object’s bytes.
Here is an example showing some back-and-forth conversions for both json and csv content types.
[com-gif-maker%20(1)]
clone the app:
https://anvil.works/build#clone:FIMSJJBV5EYKZQ7K=NJH74Q6AGAH4HHPWH7N2TVID
I’m not sure if there is an easier way, but there might be.
1 Like