開始使用免費開始

整理轉錄的電話通話資料

我們離建立文字分類器只差一步。不過目前所有轉錄後的文字資料都還在兩個清單裡:pre_purchase_textpost_purchase_text

為了更方便用來建置文字分類器,也利於之後重複使用,我們要把它們整理成一個 pandas DataFrame。

先將 pandaspd 匯入,接著使用 pd.DataFrame() 建立「購後」的資料框 post_purchase_df

我們會把一個字典傳給 pd.DataFrame():其中 "label" 鍵的值為 "post_purchase""text" 鍵的值為我們的 post_purchase_text 清單。

pre_purchase_df 也用同樣方式建立,但改用 pre_purchase_text

最後為了把所有資料放在同一個地方,使用 pd.concat() 並傳入購前與購後兩個 DataFrame。

本練習屬於課程

Python 的口語語言處理

檢視課程

練習說明

  • 使用 post_purchase_text 清單建立 post_purchase_df
  • 使用 pre_purchase_text 清單建立 pre_purchase_df
  • 使用 pd.concat() 合併這兩個 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())
編輯並執行程式碼