代码拉取完成,页面将自动刷新
import pandas as pd
class SimpleDataAnalyser:
def __init__(self):
pass
# extract property information
def extract_property_info(self, file_path):
return pd.read_csv(file_path, encoding='utf-8')
def currency_exchange(self, dataframe, exchange_rate):
trans_price = dataframe['price'].values * [exchange_rate]
return trans_price
def suburb_summary(self, dataframe, suburb):
frameGroup = dataframe.groupby(['suburb'])
if suburb == 'all':
print('>>> bedrooms describe info: ')
print(frameGroup.bedrooms.describe())
print('>>> bathrooms describe info: ')
print(frameGroup.bathrooms.describe())
print('>>> parking_spaces describe info: ')
print(frameGroup.parking_spaces.describe())
else:
if suburb not in frameGroup.suburb.groups.keys():
print('suburb is not exist')
else:
print('>>> suburb <{}> describe info: '.format(suburb))
print('>>> bedrooms describe info: ')
print(frameGroup.bedrooms.describe().loc[[suburb]])
print('>>> bathrooms describe info: ')
print(frameGroup.bathrooms.describe().loc[[suburb]])
print('>>> parking_spaces describe info: ')
print(frameGroup.parking_spaces.describe().loc[[suburb]])
def avg_land_size(self, dataframe, suburb):
frameGroup = dataframe.groupby(['suburb'])
if suburb == 'all':
dataframe = dataframe[dataframe['land_size'].apply(lambda x: x!=-1) & dataframe['land_size_unit'].apply(lambda x:x=='m²')]
frameGroup = dataframe.groupby(['suburb'])
print('>>> avg land size: ')
print(frameGroup.land_size.mean())
else:
if suburb not in frameGroup.suburb.groups.keys():
print('suburb is not exit.')
return None
else:
dataframe = dataframe[
dataframe['land_size'].apply(lambda x: x != -1) & dataframe['land_size_unit'].apply(
lambda x: x == 'm²')]
frameGroup = dataframe.groupby(['suburb'])
print('>>> suburb <{}> avg land size: {}'.format(suburb, frameGroup.land_size.mean().get(suburb)))
pass
if __name__ == '__main__':
simpleDataAna = SimpleDataAnalyser()
dataframe = simpleDataAna.extract_property_info('./property_information.csv')
print(simpleDataAna.currency_exchange(dataframe, 0.6))
# simpleDataAna.avg_land_size(dataframe, 'Balwyn')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。