Exporting data

How to export data to CSV files with Python

Using dcdcpy you can easily generate a CSV file with any data you like that's available from the Data Connector.

Our dcdcpy Python library makes all data from the Data Connector easily available as a Pandas dataFrame. The code snippet below is all you need in order to dump all the DataCamp courses to a CSV file called courses.csv

from dcdcpy.dcdcpy import DataConnector
dc = DataConnector()
courses = dc.course_dim();
courses.to_csv('courses.csv')

This way you can easily set up a recurring task to automatically generate an up to date CSV file of all the courses available on DataCamp whenever you need them.

Ofcourse there is more you can do. Say for example you only want the id, title and technology columns in the CSV. Using the filter method on the DataFrame lets you select any columns you want.

from dcdcpy.dcdcpy import DataConnector
dc = DataConnector()
courses = dc.course_dim().filter(['course_id', 'title', 'technology']);
courses.to_csv('courses.csv')

Check the article to learn what data we expose through the Data Connector.

Going one step further, if you would only be interested in Python courses, with a simple extra step you can select only the Python courses.

from dcdcpy.dcdcpy import DataConnector
dc = DataConnector()
courses = dc.course_dim().filter(['course_id', 'title', 'technology']);
courses = courses[courses['technology'] == 'Python']
courses.to_csv('courses.csv')

Last updated