Look up or assign value from another column - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Look up or assign value from another column (/thread-29151.html) |
Look up or assign value from another column - Hilda_Python - Aug-20-2020 Hi. new coder here. I have to find the oldest and newest housing block and find the price difference between them. I need to find the max/min and lookup or assign the corresponding house value from the 'house_value' column. I can't get the price difference. it keeps coming up with a tuple error. in advance, thnks. dammit, it's so easy but so hard. import pandas as pd import numpy as np import math # read datafile df=pd.read_csv ("housing_dataset.csv") df2=df[['housing_age','house_value']] #find oldest house etc oldest_house = np.max(df2) newest_house = np.min(df2) print ("The oldest house is : " , oldest_house) print ("The newest house is : " , newest_house) #find the house value x = (oldest_house, 'house_value') y = (newest_house, 'house_value') print(x) print(y) diff = x - y print(diff)
|