如何从DataFram中检索单个值

2024-09-30 16:27:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图比较两个值,得到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

Tags: csvto代码importreadinputageas