Using Google Drive in Your Colab Notebook

1. Open Google Drive and create a folder called “Data”.
Screen capture of Google Drive

2. CLick on the “New” icon on the upper left, and choose “new folder”
Screen capture of new folder selection

3. On your Drive, look for the folder “Shared with me”
Screen capture of Google Drive folder

4. You’ll see a folder called SOCY2112 if I’ve shared the folder with you. (If you don’t see SOCY2112 in the list, email me your user id for your Google account–the email you use with Google; it is usually a @gmail account but it could be any email address.) In this example, I am going to read into my Colab notebook a specific file, “ATP W89.sav”.

5. Right click on the filename, “ATP W89.sav” and select “add shortcut to Drive”.
Screen capture of creating a shortcut on Drive

6. A popup window will appear that will allow you to determine where to put the shortcut. Click on the “>” at the right of “My Drive” and you’ll a list of the folders on your drive, including the data folder you created in step 1. You can highlight “data” and click on “Add Shortcut”.
Screen capture showing how to copy the shortcut
Screen capture showing how to navigate folders to copy shortcut

7. In your Google Drive, in the Data directory, you should see a shortcut to the file “ATP W89.sav”.
Screen capture of the Data directory on Google Drive

8. In your Colab notebook, you’ll now the the file “ATP W89.sav” in the data directory. Right click on the filename, and in the popup window, select “copy path”. You can then paste the path information into the code block where you are reading in the file.
Screen capture of Colab notebook

Activity
Create a data folder in your Google Drive and create a link in it for the American Trends Panel survey data (ATP W89.sav). Copy the path in your Colab notebook to read the file into a DataFrame.

The questionnaire for this wave of the survey is here: https://drive.google.com/file/d/1Nu9sQ4Y6GIQCQH1YZfItRYNzK9ovWRY-/view?usp=sharing. You can find the demographic variables (included in all of the waves) here: https://www.pewresearch.org/wp-content/uploads/2018/05/Codebook-and-instructions-for-working-with-ATP-data.pdf

A. Formulate a research question that connects a demographic variable (such as gender, class, or race) and a belief or behavior (such as ideology or likelihood of purchasing an electric vehicle).

B. Create a table (with rp.crosstab).

C. Interpret the results.

D. What would be a good follow-up question based on your results?

Use this notebook as a guide for the code.

Author: Timothy Shortell, Ph.D.

Timothy Shortell, Ph.D., Professor & Chair, Department of Sociology, Brooklyn College CUNY