Hi I am new with python, and I would like to export files with repeated groups. These files come in 2 separate sheets. Now, with my code, I can only download 1. Has someone done something similar before?
Welcome to the community, @StephanieMilan! Interested to know on why you would like to do the same in python when it’s done so easily through the system?
Hi @Kal_Lam Thanks for the welcoming!
I am doing this through python because I have many forms (around 90) and I am downloading and cleaning the information with the code at the same time.
Hi @StephanieMilan, can you please share your code so we can take a look
Yes, sure! I was using the this structure: SEEDS/download_forms.py at main · riklinssen/SEEDS · GitHub
- I have changed the format to xls but I always get one sheet
Hi @StephanieMilan, it looks like you are using the CSV export in your script which does not support repeat groups. You will need to download the XLSX version
Yes, I changed to xlsx but I still get only one page
I changed the type_:
for uid in to_download[‘uids’]:
export=gcsv.create_export(asset=uid, username=username, passwd=passwd, domain=domain, lang=‘English (en)’, type_=‘xls’)
and then, I added:
df = pd.read_excel(to_download, sheet_name=0)
df_2 = pd.read_excel(to_download, sheet_name=1)
df['country']=countryname
df['form']=form
df['asset_id']=assetname
df['downloaded_at']=pd.Timestamp.today()
filename=form.replace("\n", "")+'.xls'
if formtype=='End of season evaluation':
data_path="path"
print(assetname, countryname, form, link, formtype)
df_all = pd.concat([df,df_2])
df_all.to_excel(data_path/filename)
But it doesn’t work too
Hi @StephanieMilan, I’m not sure what gcsv.create_export()
is doing exactly, but here is a simple example reading from a downloaded xls file:
survey
type | name | label |
---|---|---|
begin_repeat | names | Names |
text | name | What is your name? |
end_repeat |
Reading data: