TypeError:不能对<class'pandas.indexes.numeric.int64index'=“”>使用<class'str'=“”>的这些索引器[2]进行切片索引

时间:2017-04-19 13:50:31

标签: python-3.x csv

我正在尝试使用python代码执行客户分配流程 -

import time
start = time.time()
import pandas as pd
df=pd.read_csv("Cust_Data_April17.txt")
lkp=pd.read_csv("lookup_April17.csv")
df=df.sort_values(by=['alloc_cnt','alloc_id','RANKING'])
df1=df.drop_duplicates(['alloc_cnt','alloc_id','cust_id'], keep='first')
df1['alloc_id']=df1['alloc_id'].str.strip()
df4=pd.DataFrame([])
for i in range(lkp.shape[0]):
df2=df1[(lkp['alloc_cnt'][i]==df1['alloc_cnt'])&(lkp['alloc_id'][i]==df1['alloc_id'])]
    df3=df2[0:lkp['act_pct'][i]]
    df4=df4.append(df3,ignore_index=True)
df4.to_csv('Customer_Output.csv',index=False)
end = time.time()
print(end - start)

有人能说出这个程序有什么问题吗?

0 个答案:

没有答案