为什么df.fillna()只填充一些行和第一列



尝试用[]填充所有空点行和列,但是fillna()将只做一些行和第一列。我的代码在以前的运行中工作,所以我不确定发生了什么。

df = df.fillna(value = "[]")
print(df[['keywords']])
df.to_csv(r'C:Usersuserdfexport.csv', index=False, header=True)

当查看csv文件时,它看起来像:export.csv

打印语句如下:print(df[['keywords]])

import pandas as pd
import numpy as np

# initialize list of lists
data = [['tom', 10], ['',''], []]
# Create the pandas DataFrame
df = pd.DataFrame(data, columns = ['Name', 'Age'])
df.replace('', np.nan, inplace=True)
df = df.fillna(value = "[]")
print(df)

最新更新