python 使用与商店匹配的类别生成随机交易数据
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 使用与商店匹配的类别生成随机交易数据相关的知识,希望对你有一定的参考价值。
import random
method = ["credit", "debit", "credit", "credit", "debit", "credit", "credit", "cash", "credit"]
shop_dict = {
'Edgars': 'Clothing',
'CNA': 'Stationary',
'Sportmans Warehouse': 'Sports Equipment',
'Pick n Pay': 'Groceries',
'Rage Shoes': 'Shoes',
'BT Games': 'Games',
'Dions Wired': 'Electronics',
'Makro': (
'Shoes',
'Clothing',
'Electronics',
'Groceries',
'Stationary',
'Sports Equipment',
'Games'
)
}
city_dict = {
'Kroonstad': 'Free State',
'Cape Town': 'Western Cape',
'Pretoria': 'Gauteng',
'PE': 'Eastern Cape',
'Johannesburg': 'Gauteng',
'Potchefstroom': 'North West',
'Bloemfontein': 'Free State',
'Stellenbosch': 'Western Cape',
'Krugersdorp': 'Gauteng',
'Somerset West': 'Western Cape',
'Kimberley': 'Northern Cape',
'Upington': 'Northern Cape',
'Klerksdorp': 'North West',
'Potchefstroom': 'North West',
'Parys': 'Free State',
'Gauteng': 'Boksburg'
}
for x in xrange(10):
x_stores = random.choice(shop_dict.keys())
if x_stores == 'Makro':
x_category = shop_dict[x_stores][random.randint(0,6)]
else:
x_category = shop_dict[x_stores]
x_cities = random.choice(city_dict.keys())
x_province = city_dict[x_cities]
print (
str(random.randint(1, 1000)).zfill(4) + ',' +
str(random.randint(2014,2016)) + '-' + str(random.randint(1,12)).zfill(2) + '-' + str(random.randint(1,28)).zfill(2) + ',' +
str(random.randint(4000000,4001000)) + ',' +
str(random.randint(29, 800)) + '.' + str(random.randint(0, 99)).zfill(2) + ',' +
x_stores + ',' +
x_category + ',' +
x_cities + ',' +
x_province + ',' +
random.choice(method)
)
# Schema: AccountID, DateOfPurchase, TransactionID, PurchasePrice, StoreName, StoreCategory, CityName, ProvinceName, PurchaseMethod
以上是关于python 使用与商店匹配的类别生成随机交易数据的主要内容,如果未能解决你的问题,请参考以下文章
使用python爬取App安卓应用商店评论并生成词云
使用python爬取App安卓应用商店评论并生成词云
使用python爬取App安卓应用商店评论并生成词云
Hive查询:匹配列数组的字符串值以生成标志
如何在excel中随机生成数据
Asp.net - 用于存储字典的缓存与静态变量