加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
SimpleDataAnalyser.py 2.57 KB
一键复制 编辑 原始数据 按行查看 历史
psychofu 提交于 2023-10-21 07:46 . add main file content
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')
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化