DataWhale Python_analysis Day1

本文介绍了如何在Google Colab上加载数据集,包括挂载Google Drive,使用Kaggle API下载数据到MyDrive,以及数据的初步观察和处理。详细讲述了判断数据空值的方法和Pandas中轴的概念。
摘要由CSDN通过智能技术生成

Google Colab 平台加载数据集

mount google drive

from google.colab import drive

drive.mount('/content/gdrive/')
Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=947318989803-6bn6qk8qdgf4n4g3pfee6491hc0brc4i.apps.googleusercontent.com&redirect_uri=urn%3aietf%3awg%3aoauth%3a2.0%3aoob&response_type=code&scope=email%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdocs.test%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive.photos.readonly%20https%3a%2f%2fwww.googleapis.com%2fauth%2fpeopleapi.readonly

Enter your authorization code:
··········
Mounted at /content/gdrive/

download kaggle.json

!pip install kaggle
Requirement already satisfied: kaggle in /usr/local/lib/python3.6/dist-packages (1.5.6)
Requirement already satisfied: tqdm in /usr/local/lib/python3.6/dist-packages (from kaggle) (4.41.1)
Requirement already satisfied: requests in /usr/local/lib/python3.6/dist-packages (from kaggle) (2.23.0)
Requirement already satisfied: urllib3<1.25,>=1.21.1 in /usr/local/lib/python3.6/dist-packages (from kaggle) (1.24.3)
Requirement already satisfied: six>=1.10 in /usr/local/lib/python3.6/dist-packages (from kaggle) (1.15.0)
Requirement already satisfied: certifi in /usr/local/lib/python3.6/dist-packages (from kaggle) (2020.6.20)
Requirement already satisfied: python-dateutil in /usr/local/lib/python3.6/dist-packages (from kaggle) (2.8.1)
Requirement already satisfied: python-slugify in /usr/local/lib/python3.6/dist-packages (from kaggle) (4.0.1)
Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.6/dist-packages (from requests->kaggle) (2.10)
Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from requests->kaggle) (3.0.4)
Requirement already satisfied: text-unidecode>=1.3 in /usr/local/lib/python3.6/dist-packages (from python-slugify->kaggle) (1.3)
from google.colab import files
files.upload()
 <input type="file" id="files-43da6c52-9c50-46bc-a3ef-917ec76f55a7" name="files[]" multiple disabled
    style="border:none" />
 <output id="result-43da6c52-9c50-46bc-a3ef-917ec76f55a7">
  Upload widget is only available when the cell has been executed in the
  current browser session. Please rerun this cell to enable.
  </output>
  <script src="/nbextensions/google.colab/files.js"></script> 


Saving kaggle.json to kaggle.json





{'kaggle.json': b'{"username":"*********","key":"**********************"}'}
!mkdir -p ~/.kaggle        # https://blog.csdn.net/qq_15037231/article/details/77717272
!cp kaggle.json ~/.kaggle
!chmod 600 ~/.kaggle/kaggle.json

通过API将数据下载到MyDrive

!kaggle competitions download -c titanic -p '../content/drive/My Drive'
Warning: Looks like you're using an outdated API Version, please consider updating (server 1.5.6 / client 1.5.4)
Downloading gender_submission.csv to ../content/drive/My Drive
  0% 0.00/3.18k [00:00<?, ?B/s]
100% 3.18k/3.18k [00:00<00:00, 450kB/s]
Downloading train.csv to ../content/drive/My Drive
  0% 0.00/59.8k [00:00<?, ?B/s]
100% 59.8k/59.8k [00:00<00:00, 8.44MB/s]
Downloading test.csv to ../content/drive/My Drive
  0% 0.00/28.0k [00:00<?, ?B/s]
100% 28.0k/28.0k [00:00<00:00, 3.96MB/s]
!mkdir -p ~/content/drive/My Drive/Titanic/

#!rm -rf /content/Drive/Titanic       /content/Drive/Titanic
#!rm -rf /content/Drive
import os

os.getcwd()
'/content'
!ls
#/content/Drive/Titanic
drive  Drive  gdrive  kaggle.json  sample_data
#!mkdir -p ../content/drive/My Drive/Titanic/

mkdir: cannot create directory ‘../content/drive/My’: Operation not supported
!mv /content/drive/My Drive/gender_submission.csv /content/Drive/Titanic/
mv: cannot stat '/content/drive/My': No such file or directory
mv: cannot stat 'Drive/gender_submission.csv': No such file or directory
import os
path = '/content/drive/My Drive'

os.chdir(path)
os.listdir(path)
['Colab Notebooks',
 'Linux_python',
 'Cmd Markdown 编辑阅读器 - 作业部落出品.png',
 'Kaggle',
 'Untitled0.ipynb',
 'Learning-from-data.gz',
 'Wind quant',
 'DL',
 'python_vs_ML',
 'SQL+经典实例.pdf',
 'test1',
 '.ipynb_checkpoints',
 'Tiantic']
aos.getcwd()
'/content/drive/My Drive'
!ls
'Cmd Markdown 编辑阅读器 - 作业部落出品.png'
'Colab Notebooks'
 DL
 gender_submission.csv
 Kaggle
 Learning-from-data.gz
 Linux_python
 python_vs_ML
 SQL+经典实例.pdf
 test1
 test.csv
 train.csv
 Untitled0.ipynb
'Wind quant'
os.getcwd()
'/content/drive/My Drive'
!mkdir ./Tiantic/
!mv ./train.csv ./Tiantic/
!mv ./test.csv ./Tiantic/
!mv ./gender_submission.csv ./Tiantic
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值