开始使用免费开始使用

整理转写后的电话通话数据

我们已经快可以构建文本分类器了。不过目前,所有转写后的文本数据还分散在两个列表中:pre_purchase_textpost_purchase_text

为便于构建文本分类器,也便于后续复用,我们将它们整合到一个 pandas DataFrame 中。

首先导入 pandas 并命名为 pd,然后使用 pd.DataFrame() 创建一个购买后数据的 DataFrame,命名为 post_purchase_df

pd.DataFrame() 传入一个字典,其中包含键 "label",取值为 "post_purchase",以及键 "text",取值为我们的 post_purchase_text 列表。

pre_purchase_df 也做同样的处理,但将 text 的取值换为 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())
编辑并运行代码