![見出し画像](https://assets.st-note.com/production/uploads/images/93908576/rectangle_large_type_2_dfe92c9ac0baf27a796bcf0ca88ad77d.jpeg?width=1200)
【Python】read_pickleからto_csvして、テキストファイル生成【Colaboratory】
read_pickleからto_csvして、テキストファイル生成。
Google Drive
from google.colab import drive
drive.mount('/content/drive/')
%mkdir "/content/drive/My Drive/text/"
%cd "/content/drive/My Drive/text/"
textというフォルダを作成し、cdでそのフォルダに移動しておく。
※フォルダ=ディレクトリ
#読み込み(dataフォルダ内にあるピッケルファイルを読み出し)
df_pkl = pd.read_pickle('data/df_marge.pkl')
#いらない文字があったのでリプレイス
df_pkl.replace('\n\n\n\xa0', key_Buy,inplace=True)
#df_pklのカラム名hにある大文字を小文字にする
df_pkl['h'] = df_pkl['h'].str.lower()
#df_pklのカラム名contentにある大文字を小文字にする
df_pkl['content'] = df_pkl['content'].str.lower()
df_pkl.to_csv('ファイル名.txt')
どんな時に使ったかメモ
スクレイピングしたデータをピッケルファイルで保存していたが、GPT2のファインチューニング時にテキスト化するのと、大文字小文字を変換したほうがGPTの出力が安定することに気付き作成。
大文字小文字変換のエラーの対処
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
こちらより
いいなと思ったら応援しよう!
![ムジン #サイト改善コンサル #SEO対策 #マーケティング戦略](https://assets.st-note.com/production/uploads/images/72204260/profile_523cf9118a40d52a5b35595afde65377.png?width=600&crop=1:1,smart)