Import Kaggle Datasets to Google Colab
Having trouble using your Kaggle data in Google Colab? Don’t worry, this guide will help!
Preparation
Make sure you have accounts on both Kaggle and Google Colab (and are logged in).
Above is a Kaggle dataset that I want to use. Click here to go to the Kaggle dataset page. Or you can open any Kaggle dataset that you want to work with.
Getting the Kaggle API Key
Next step, you have to get the kaggle.json file from your Kaggle profile. Click on your Kaggle profile and click “Settings”. After that, you will see your settings page and scroll down until you see the API section. In that section, you can see the “Create New Token” button, click the button and the kaggle.json file will be downloaded.
Now, create a Google Colab notebook and move the kaggle.json file into the Google Colab directory files. Next, type this to install Kaggle on your Google Colab environment.
pip install kaggle
once the Kaggle is installed, add a new code line and type this to download your Kaggle Dataset. You can change “bwandowando/spotify-songs-with-attributes-and-lyrics” into your desired Kaggle datasets link.
!kaggle datasets download -d bwandowando/spotify-songs-with-attributes-and-lyrics
Once the dataset is downloaded, you can unzip the dataset by typing on this command. You can change “/content/spotify-songs-with-attributes-and-lyrics.zip” with your download directory
!unzip /content/spotify-songs-with-attributes-and-lyrics.zip
If you are not sure where your file is, you can right-click on the downloaded file and then choose “Copy Path” to get the right file directory and then paste it.
After the file has been unzipped, you can see that there are new folders made within Google Colab files. Now, add a new code line and type this to read the imported datasets and run it.
import pandas as pd
df_attributes = pd.read_csv('/content/songs_with_attributes_and_lyrics.csv/songs_with_attributes_and_lyrics.csv')
df_attributes.head()
And your imported dataset is ready to be used. Have fun working with your data!
Now you can use your imported data for various tasks like sentiment analysis, genre classification, and more!