I want to receive a value as input and store the value of the for statement by year in the data frame.
Trying to repeat for 10 years from 2019
Middle-aged housing amount in 2019 --> 2013 average / young housing value in 2009 --> 2019 average / middle-aged housing value in 2014 --> divided by two values
In 2018, the 2008-2012 average / 2013-2018 average / divided by two values
I'd like to calculate the reduced value of the year in this way.
path = r'C:\Users\admin\Desktop\Python\Legal East Code_Full Material.xlsx'
code_df=pd.read_excel(path)
x=input ('Enter the address you want to find:') #Enter it in Korean to find the code to substitute it
code_select_df = code_df[code_df['waste' == 'exist']
code_sample_df = code_select_df[code_select_df['legal name'] == x]
code_sample_df["Court Code"]
code = code_sample_df["Court Code"]
x=str(cod.iloc[0])
x=x[0:5] #Only 5 digits out of the long legal code are required
y=int(input('Enter base year:')))
df_base=pd.DataFrame (columns=[year], 'middle-aged housing value', 'young housing price', 'middle-aged housing price'])
for j in range(0,10):
k=y-j
price_df=get_year_realprice('x','str(k)')
#Enter middle-aged housing value calculation year
temp=price_df["dedicated area"]
price_df['exclusive area']=pd.to_numerical(temp)
temp = price_df ['transaction amount'].apply(lambda x: x.replace(',', '') )
price_df['transaction amount'] = pd.to_numerical(temp)
price_df['fair unit price'] = price_df['transaction amount'] / price_df['exclusive area'] / 3.3
temp=price_df['architectural year']
price_df['construction year']=pd.to_numerical(temp)
price_new_df = price_df[price_df['building year'] >=int(k)-4]
#Based on young housing = within 5 years of completion
price_select_df = price_df[price_df['architectural year'] >= int(k)-9]
price_old_df = price_select_df[price_select_df['building year']<= int(k)-5]
#Based on middle-aged housing = within 6-10 years of completion
old_price = np.mean (price_old_df['per-price'])
new_price = np.mean (price_new_df['per-price'])
mah_value=(old_price/new_price)
df_base=df_base.append(pd.DataFrame([str(k), mah_value, new_price, old_price]), columns=['year', 'middle-aged housing value', 'young housing price', 'middle-aged housing price'], and ignore_index=true)
df_base
Get_year_realprice is defined above and appears to be working well. (It's a code that already exists, so I wrote it right away)
def get_realprice(code, date):
url = 'http://openapi.molit.go.kr:8081/OpenAPI_ToolInstallPackage/service/rest/RTMSOBJSvc/getRTMSDataSvcAptTrade'
key = 'NfQ7K6WgSudMMtb8YT5AC3%2FrDhHvg%2BZupj%2Fy4fze4XxJ61XctYdvZEc5wNFrqargp5yLGQwRw7RY16eCAebIbg%3D%3D'
real_url = url +'?'+ 'LAWD_CD={}&DEAL_YMD={}&serviceKey={}'.format(code, date, key)
data = requests.get(real_url)
data_bs = bs4.BeautifulSoup(data.text, 'lxml-xml')
item_list = data_bs.find_all('item')
Transaction amount list = []
Year of Architecture List = []
Year List = []
Wallist = []
Ilist = []
List of legal dongs = []
Apartment List = []
Dedicated Area List = []
Layer List = []
Landlord list = []
Regional Code List = []
for item in item_list:
Transaction amount list.append(item.find('transaction amount')).text)
A list of architectural years.text)
Year list.append(item.find('year')).text)
Wallist.append(item.find('month').text)
Illist.append(item.find('work')).text)
The list of legal dongs.append(item.find('legal dong')).text)
The apartment list.append.text)
Dedicated area list.append(item.find('dedicated area')).text)
a floor listappend(item.find('layer')).text)
a lot number listappend(item.find('lot number').text)
Regional code list.append(item.find('regional code').text)
result_df = pd.DataFrame({'transaction amount'):transaction amount list,
'Architectural Year': Architectural Year List 'Year': Year List, Month': Wallist, Day': Ilist,
Beopjeong-dong': Beopjeong-dong list, 'apartment': apartment list, 'exclusive area': exclusive area list,
'Layer':Layer list, 'Location number':Location list, 'Region code':Region code list})
return result_df
def get_year_realprice(code, year):
year_list = []
for i in range(1, 13):
if i < 10:
temp_date = year + '0' + str(i)
else:
temp_date = year + str(i)
year_list.append(get_realprice(code, temp_date))
year_df = pd.concat(year_list)
year_df = year_df.reset_index()
del year_df['index']
del year_df ["Court Rocks"]
del year_df ["Apartment"]
del year_df ["Layer"]
"Del year_df" ["Zone"Zone"
del year_df ["work"]
delyear_df["Region Code"]
return year_df
I'd really appreciate your help!
python dataframe pandas
I think it's going well.
Since k is int, I think we only need to correct the int(k) part, but it is not an error, so there is no problem with execution...But what's the question?
2019
Yearly middle-aged housing value Young housing price Middle-aged housing price
0 2019 0.518687 413.246439 214.345396
1 2018 0.688188 287.400592 197.785632
2 2017 0.810316 230.767602 186.994569
3 2016 0.922552 182.836190 168.675836
4 2015 1.099251 145.339986 159.765101
5 2014 1.165235 133.570693 155.641223
6 2013 0.856553 158.622049 135.868213
7 2012 1.022391 133.735333 136.729819
8 2011 1.108385 135.849155 150.573229
9 2010 0.990234 150.722783 149.250750
2018
Yearly middle-aged housing value Young housing price Middle-aged housing price
0 2018 0.688188 287.400592 197.785632
1 2017 0.810316 230.767602 186.994569
2 2016 0.922552 182.836190 168.675836
3 2015 1.099251 145.339986 159.765101
4 2014 1.165235 133.570693 155.641223
5 2013 0.856553 158.622049 135.868213
6 2012 1.022391 133.735333 136.729819
7 2011 1.108385 135.849155 150.573229
8 2010 0.990234 150.722783 149.250750
9 2009 0.999133 147.929649 147.801344
If you use pycharm or visual studio code, old_price =...Set the breakpoint on the
line, run it in debug mode, and follow one line at a time.
621 GDB gets version error when attempting to debug with the Presense SDK (IDE)
579 Understanding How to Configure Google API Key
575 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
926 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.