我试图比较两个值,得到Value Error: Series lengths must match to compare
。下面是我的代码
import pandas as pd
import csv
import numpy as np
Input = pd.read_csv('C:/PyTemp/IN.csv')
Template = pd.read_csv('C:/PyTemp/Length.csv')
Start = pd.merge(Template, Input, on = 'AGE', how = 'left')
InitialAge = Input['AGE']
loopcount = 105
i = 1
while i < loopcount:
Start.ix[Start.AGE > InitialAge, 'SI'] = Start['SI'].shift()
i += 1
Start.to_csv('C:/PyTemp/' + 'Output' + '.csv', header = True)
当我代课时:
while i < loopcount:
Start.ix[Start.AGE > 16, 'SI'] = Start['SI'].shift()
i += 1
代码正常工作
print(InitialAge)
print(Start.AGE)
收益率
0 16
Name: AGE, dtype: int64
0 1
0 2
---
0 105
Name: AGE, dtype: int64
你的
InitialAge
是一个pandas.Series
,而不是一个integer
,这是你可能正在寻找的请尝试:
相关问题 更多 >
编程相关推荐