Python 读取 CSV 文件并筛选前 5000 条非空数据
你可以使用 Python 中的 pandas 库来读取 csv 文件,并筛选出前 5000 条 'content_word' 非空的数据。以下是一个示例代码:
import pandas as pd
# 读取 csv 文件
df = pd.read_csv('comment.csv')
# 筛选出 'content_word' 非空的数据
df_filtered = df[df['content_word'].notnull()]
# 获取前 5000 条数据
df_filtered = df_filtered.head(5000)
# 打印筛选结果
print(df_filtered)
请确保 'comment.csv' 文件与你的 Python 代码在同一目录下,并且文件名和路径正确。
原文地址: https://www.cveoy.top/t/topic/pgI6 著作权归作者所有。请勿转载和采集!