如果设置
dtype=object,则系列将能够包含任意数据类型:
df["int"] = pd.Series([], dtype=object)df["str"] = pd.Series([], dtype=str)df.loc[0] = [0, "zero"]print(df)print()df.loc[1] = [1, None]print(df) int str0 0 zero1 NaN NaN int str0 0 zero1 1 None

如果设置
dtype=object,则系列将能够包含任意数据类型:
df["int"] = pd.Series([], dtype=object)df["str"] = pd.Series([], dtype=str)df.loc[0] = [0, "zero"]print(df)print()df.loc[1] = [1, None]print(df) int str0 0 zero1 NaN NaN int str0 0 zero1 1 None