136 - 名無しさん@転載禁止 2023/03/31(金) 07:35:00.97 ID:UrnYU53k0副
これでdfにできてる
# カラム名の指定
columns = ["key", "thread_title", "res_num", "name", "email", "comment_date", "post_id", "comment"]
# データ型の指定
dtype = {"key": "Int64", "thread_title": str, "res_num": "Int64", "name": str, "email": str, "comment_date": str, "post_id": str, "comment": str}
# CSVファイルの読み込み
df = pd.read_csv(csv_path, names=columns, dtype=dtype, parse_dates=["comment_date"], na_values=[""])
# 欠損値の埋め方を指定
df = df.fillna({"key": 0, "res_num": 0})
# 「Over 1000」を除外
df = df[df["comment_date"] != "Over 1000"]
# comment_dateカラムを日付型に変換
df["comment_date"] = pd.to_datetime(df["comment_date"], format="%Y/%m/%d(%a) %H:%M:%S.%f")