# 将表格的列标题作为第一行, 转为二维list
# 情况1_1, 表格, 无数据; 情况1_2, 表格, 有数据
data = [[1,1]]
columns = ['col1', 'col2']
df = pd.DataFrame(data=data, columns=columns)
df_concat = pd.concat([
# to_frame(index: 'bool' = True, name: 'Hashable' = <no_default>)
df.columns.to_frame().T,
df
]).reset_index(drop=True)
display(df_concat)
# 情况2_1, series, 无列名; 情况2_2, series, 有列名
data = [1, 1]
name = 'ser_name'
ser = pd.Series(data, name=name)
# futurewarning None dtype will be object instead of now float64
ser_name = pd.Series(ser.name)
pd.concat([ser_name, ser])
标签:第一行,name,表格,df,list,pd,data,columns,ser
From: https://blog.51cto.com/u_16055028/8631530