数据准备
import pandas as pd
df = pd.DataFrame([['L123','A'],
['L456','A'],
['L437','C']
],columns=['Raw Material','Level'])
df
方法1:pandas.DataFrame.reindex()
import pandas as pd
df = pd.DataFrame([['L123','A'],
['L456','A'],
['L437','C']
],columns=['Raw Material','Level'])
df = df.reindex(columns = df.columns.tolist() + ["Data1","Data2",'Data3'])
df
方法2:直接创建空值列
import pandas as pd
import numpy as np
df = pd.DataFrame([['L123','A'],
['L456','A'],
['L437','C']
],columns=['Raw Material','Level'])
df["Data1"] = ""
df["Data2"] = np.nan
df['Data3'] = pd.Series()
df
方法3:pandas.DataFrame.assign()
import pandas as pd
import numpy as np
df = pd.DataFrame([['L123','A'],
['L456','A'],
['L437','C']
],columns=['Raw Material','Level'])
df = df.assign(Data1 = np.nan, Data2 = "", Data3 = pd.Series())
df
方法4:pandas.DataFrame.insert()
import pandas as pd
import numpy as np
df = pd.DataFrame([['L123','A'],
['L456','A'],
['L437','C']
],columns=['Raw Material','Level'])
df.insert(2, "Data1", pd.Series())
df.insert(3, "Data2", np.nan)
df.insert(4, "Data3", "")
df
扩展补充资料
[Pandas技巧] 添加新列https://blog.csdn.net/Hudas/article/details/125349965