加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
DataVisualiser.py 2.18 KB
一键复制 编辑 原始数据 按行查看 历史
psychofu 提交于 2023-10-22 05:35 . update DataVis.. method
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib as mp
mp.use('TkAgg')
class DataVisualiser:
def __init__(self):
pass
def prop_val_distribution(self, dataframe, suburb, target_currency):
currency_dict = {
'AUD': 1,
'USD': 0.66,
'INR': 54.25,
'CNY': 4.72,
'JPY': 93.87,
'HKD': 5.12,
'KRW': 860.92,
'GBP': 0.51,
'EUR': 0.60,
'SGD': 0.88
}
if suburb not in dataframe.groupby(['suburb']).suburb.groups.keys():
print('suburb <{}> is not exist, print all suburb'.format(suburb))
data = dataframe.price.values
else:
data = dataframe[dataframe['suburb'] == suburb].price.values
if currency_dict.get(target_currency):
rate = currency_dict.get(target_currency)
data = data * rate
else:
print('target_currency is not exist, use default value AUD')
# filter data, remove nan value
filterArr = []
for elem in data:
if str(elem) == 'nan':
filterArr.append(False)
else:
filterArr.append(True)
newData = data[filterArr]
plt.hist(newData, bins=30, color='skyblue', alpha=0.8)
plt.title('Histogram')
plt.xlabel('value')
plt.ylabel('frequency')
plt.savefig('./histogram.jpg')
plt.show()
def sales_trend(self, dataframe):
soldDate = dataframe.sold_date.values
m = {}
for v in soldDate:
if str(v) != 'nan':
year = v.split('/')[-1]
if m.get(year):
m[year] = m[year] + 1
else:
m[year] = 1
x = []
y = []
for i in sorted(m):
x.append(i)
y.append(m[i])
plt.title('sold line')
plt.xlabel('year')
plt.ylabel('sold number')
plt.plot(x, y)
plt.show()
pass
if __name__ == '__main__':
dataframe = pd.read_csv('./property_information.csv')
demo = DataVisualiser()
demo.prop_val_distribution(dataframe, 'all', 'CNY')
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化