这是问题所在。我有一个看起来像这样的数据框
df1 = pd.read_excel('excelA.xlsx')
df2 = pd.read_excel('excelB.xlsx')
ind = df1['some_col']
cols = df2.columns
# Using index from df1 and columns from df2 create a new df
res_df = pd.DataFrame(index=ind, columns=cols)
# Inserting values from df2 into new df
for c in cols:
for j in range(len(df2[c])):
res_df[c].iloc[j] = df2[c].iloc[j]
print(res_df.index) // Index([something, something2, something3 ... ])
writer = pd.ExcelWriter('test.xlsx', engine='xlsxwriter')
res_df.to_excel(writer, sheet_name='Sheet1', index=True)
writer.close()
现在我尝试阅读文件
df = pd.read_excel('test.xlsx', dtype=str)
print(df.index) // RangeIndex(start=0, stop=1000, step=1)
谁能告诉我这里发生了什么?
答案 0 :(得分:0)
签入excel什么是索引列的列索引。
然后使用pd.read_excel(''test.xlsx',index_col = [index_in_excel])