0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

GoogleColab×DataScience

Last updated at Posted at 2023-07-01

本記事では、GoogleColab上で、データサイエンス(分析, 可視化)に取り組む際の参照コードを集めています。

GitHub

DataFrame×JSONL

  • JSONLファイルをDataFrameへ読み込む
      df = pd.read_json('readfile.jsonl', orient='records', lines=True)
      df.head()
    
  • DataFrameをJSONLファイルへ書き込む
      df.to_json('writefile.jsonl', orient='records', lines=True, force_ascii=False)
    

DataFrame×GoogleSpreadseets

  • GoogleSpreadseetsをDataFrameへ読み込む
    #spreadsheets認証
    from google.colab import auth
    auth.authenticate_user()
    
    import gspread
    from google.auth import default
    creds, _ = default()
    
    gc = gspread.authorize(creds)
    
    #spreadsheets-URL
    url = "[URL]"
    ss = gc.open_by_url(url)
    
    #spreadsheet指定
    st = ss.get_worksheet(0)
    
    #データフレーム化
    import pandas as pd
    df = pd.DataFrame(st.get_all_values())
    df.columns = list(df.loc[0, :])
    df.drop(0, inplace=True)
    df.reset_index(inplace=True)
    df.drop('index', axis=1, inplace=True)
    
    df.head()
    

Download

!zip -r dirname.zip dirname
from google.colab import files
files.download('dirname.zip')
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?