将空列添加到pandasDataFrame对象的最简单方法是什么?我偶然发现的最好的东西是
DataFrame
df['foo'] = df.apply(lambda _: '', axis=1)
有没有那么不合常理的方法?
如果我理解正确,则应填写作业:
>>> import numpy as np >>> import pandas as pd >>> df = pd.DataFrame({"A": [1,2,3], "B": [2,3,4]}) >>> df A B 0 1 2 1 2 3 2 3 4 >>> df["C"] = "" >>> df["D"] = np.nan >>> df A B C D 0 1 2 NaN 1 2 3 NaN 2 3 4 NaN