Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about exporting field labels #19

Closed
murphyke opened this issue Aug 29, 2013 · 2 comments
Closed

Question about exporting field labels #19

murphyke opened this issue Aug 29, 2013 · 2 comments

Comments

@murphyke
Copy link

If you do a manual REDCap export, you have the choice of "labels" or "raw", which affects the column headings, e.g. a choice between "More than one race (choice='White')" and "race_multi___1", for a column for a dropdown-type field whose name is "race_multi" and whose label is "More than one race".

The PyCap documentation claims:

# Same data, but keys will the field labels
data = project.export_records(raw_or_label='label')

However, in the code, it suggests that this option actually controls the values, not the keys, and I saw no difference in the field keys.

Also, the code made it sound like the event_name option might control the use of field labels as keys, but I didn't see that it affected the returned results at all. (My data is in a "classic" repository database project, BTW).

I was hoping to reproduce the effects of a manual export with labels, but it seems that will take a little work (to apply labels, order the fields, etc).

@murphyke
Copy link
Author

I see now that the behavior is determined by the REDCap API, not by PyCap. That one bit of documentation could stand to be clarified, however.

@sburns
Copy link
Collaborator

sburns commented Sep 3, 2013

Thanks for the doc suggestion, @murphyke. You might consider something like this to get you 90% towards a manual export through the API…

project = Project(foo, bar)
field_to_label = {f['field_name']: f['field_label'] for f in project.metadata}
df = project.export_records(format='df')
df = df.rename(columns=field_to_label)
df.to_csv('exported.csv', index_label=project.def_field)

The ordering is difficult to ensure. Also, all the [form_name]_complete columns will not be renamed. Form status fields are unfortunately not in the data dictionary. You might use project.forms to add renaming keys to the field_to_label dict.

Note, the above requires the pandas library. You could just as easily double-loop through the records and keys, but pandas makes so many things so easy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants