文字起こしした電話対応データの整理
テキスト分類器を作る準備がほぼ整いました。ただし現時点では、文字起こししたテキストは pre_purchase_text と post_purchase_text の2つのリストに分かれています。
テキスト分類器の構築や今後の活用のために、これらを1つの pandas DataFrame にまとめて整理しましょう。
まず pandas を pd としてインポートし、pd.DataFrame() を使って購入後データのDataFrameである post_purchase_df を作成します。
pd.DataFrame() には、"label" キーに "post_purchase"、"text" キーに post_purchase_text リストを指定した辞書を渡します。
pre_purchase_df についても同様に、pre_purchase_text を使って作成します。
すべてのデータを1か所にまとめるため、pd.concat() を使って購入前後のDataFrameを結合します。
この演習はコースの一部です
Pythonで学ぶ音声言語処理
演習の手順
post_purchase_textリストを使ってpost_purchase_dfを作成します。pre_purchase_textリストを使ってpre_purchase_dfを作成します。pd.concat()を使って2つのDataFrameを結合します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
import pandas as pd
# Make dataframes with the text
post_purchase_df = pd.DataFrame({"label": "post_purchase",
"text": ____})
pre_purchase_df = pd.____({"label": "pre_purchase",
"text": ____})
# Combine DataFrames
df = pd.____([post_purchase_df, pre_purchase_df])
# Print the combined DataFrame
print(df.head())