Writing data to a data source

You can write Cognos Analytics data in a notebook using the Python or R programming languages.

You can save or create the data source in My content or Team content.

To write data to the data source, specify the following code in a notebook cell:
In Python
data = CADataConnector.write_data(parameters as described in the following sections)
Parameter Required or optional Description
data required

Pandas.DataFrame. Contains the table of data, which is written to the file.

path

id

Specify one of path or id
Path to the data source. If the data source is in My content, specify .my_folders at the start of the path. If the data source is in Team content, specify .public_folders at the start of the path. For example, to specify a file called sales-notebook that is stored in My content, specify
path=".my_folders/sales-notebook"
The ID of the file. For information about how to get the ID of a file, see Finding the ID of a file. For example:
id="i1F8D76C0FAD34J9CA50118746935D9X7"
mode optional
x
Create the file and write to it. If the file exists, the method fails with an exception. Default value.
w
Overwrite any data that exists in the file. The columns that you are writing to the file must match the ones in the file. Create the file if it doesn't exist.
a
Append to the end of the file. The columns that you are adding to the file must match the ones in the file. Create the file if it doesn't exist.
Example:
mode="w"
Note: You can use either single or double quotation marks in a method but not a mix of both.

For examples of how to code the write_data() method, see Python notebook examples and R notebook examples.