不能将<function array_str at 0x02F1E978>转换为Excel

即使我试图将所有东西都转换成对象或string,我仍然得到上面的错误。

df['temp'] = df['Date'].apply(lambda x: x.strftime('%m/%d/%Y')) nd = df['Date'].unique() nd = np.array_str 

我想获得df的Date列中的唯一值作为列标题。 我想要这个值显示为MM / DD / YYYY。 Python中的结果显示为“0x02F1E978”。 应该是09/25/2017,我可以把文件写入Excel。

 import pandas as pd import numpy as np from datetime import date, datetime path = 'C:/Users/tnguy075/Desktop/Inventory Valuation/' file1 = 'AH_INDY_COMBINEDINV_VALUE_TIDL.xlsx' file2 = 'DailyInventoryVal.xlsx' df = pd.read_excel(path+file1, skiprows=1, dtype={'Valuation': np.float64}, parse_dates=['Date']) #open the daily data df['temp'] = df['Date'].apply(lambda x: x.strftime('%m/%d/%Y'))#change it to a string in form of MM/DD/YYYY nd = df['Date'].unique() nd = np.array_str df = pd.pivot_table(df,index=["Key"], values=["Valuation"],aggfunc=np.sum).reset_index() df.columns = ['Key',nd] dv = pd.read_excel(path+file2) dv = dv.merge(df[['Key', nd]], how = 'left')#Merge data from file 1 using Key dv.to_excel('path+DaivalReport.xlsx')