kharn
kharn

Reputation: 83

How to retrieve individual value from DataFrame

I am trying to compare two values, and am getting Value Error: Series lengths must match to compare. Below is my code.

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)

When I subsitute:

while i < loopcount:
    Start.ix[Start.AGE > 16, 'SI'] = Start['SI'].shift()
    i += 1

The code works properly.

print(InitialAge)
print(Start.AGE)

Yields

0    16
Name: AGE, dtype: int64

0    1
0    2
---
0    105
Name: AGE, dtype: int64

Upvotes: 1

Views: 65

Answers (1)

Stefan
Stefan

Reputation: 42885

Your InitialAge is a pandas.Series, not an integer, which is what you are probably looking for.

Try instead:

InitialAge = Input.get_value(0, 'AGE')

Upvotes: 2

Related Questions