我目前正在尝试预测客户在下一个时间段内可能购买的下一个商品序列。以下示例仅用于说明目的(我的实际数据集有大约600万个客户ID和5000种不同的产品)
我当前的数据如下所示:
date customer_nbr products_bought
201701 123 ["product_1","product_5","product_15"]
201704 123 ["product_4","product_10","product_11"]
201721 123 ["product_1","product_6"]
201713 456 ["product_7","sproduct_11","product_12","product_15"]
201714 456 ["product_1","product_3"]
201721 456 ["product_4","product_9","product_10","product_13","product_15"]
Run Code Online (Sandbox Code Playgroud)
数据的频率按周。因此,customer_id 123在2017年的第一周购买了商品“ product_1”,“ product_5”和“ product_15”(因此,给定年份最多有52周)。滞后获取我的输入变量后,我的最终数据帧如下所示:
date customer_nbr products_bought_last_period products_bought
201704 123 ["product_1","product_5","product_15"] ["product_4","product_10","product_11"]
201721 123 ["product_4","product_10","product_11"] ["product_1","product_6"]
201714 456 ["product_7","sproduct_11","product_12","product_15"] ["product_1","product_3"]
201721 456 ["product_1","product_3"]
["product_4","product_9","product_10","product_13","product_15"]
Run Code Online (Sandbox Code Playgroud)
因此,对于我的seq2seq模型,我想预测客户使用来购买日期为201721的产品的顺序products_bought_last_period,因此这products_bought_last_period是我的输入,products_bought现在是我的目标变量。然后,我对产品ID进行编码,products_bought_last_period并products_bought在数据框中填充和数组(基于具有最多产品的数组)。之后,我将所有内容都转换为np.arrays。最后,我的实际数据集中的产品总数为5000,因此我进行设置total_nbr_of_products = 5000并尝试执行以下操作:
train = df[df['date'] < 201721].set_index('date')
test = df[df['date'] >= 201721].set_index('date')
X = train["products_bought_last_period"].copy()
X_test = test["products_bought_last_period"].copy()
y …Run Code Online (Sandbox Code Playgroud) 我正在尝试通过实现以下方法组合多个shapefile:
import geopandas as gpd
import pandas as pd
for i in range(10,56):
interesting_files = "/Users/m3105/Downloads/area/tl_2015_{}_arealm.shp".format(i)
gdf_list = []
for filename in sorted(interesting_files):
gdf_list.append(gpd.read_file((filename)))
full_gdf = pd.concat(gdf_list)
Run Code Online (Sandbox Code Playgroud)
其中目录/Users/m3105/Downloads/area有多个shapefile,例如tl_2015_01_arealm.shp,tl_2015_02_arealm.shp一直到最多tl_2015_56_arealm.shp.我想结合所有这些shapefile,避免重复他们的标题.但是,每当我尝试使用上面的代码连接文件时,我会收到以下错误:
ValueError: Null layer: u''
通常,我知道如何连接csv文件,但我注意到如何连接shapefile.我非常感谢任何帮助
我非常感谢有关以下问题的任何反馈.到目前为止,我在Python上编写了一个代码,它生成了二维元组的组合,其中每个元素都是1到4的值.因此对于(a1,a2),a1和a2可以是1到4之间的任何值
因此,这产生了以下元组
tuple_combinations = [(1, 1), (1, 2), (1, 3), (1, 4), (2, 1), (2, 2), (2, 3), (2, 4), (3, 1), (3, 2), (3, 3), (3, 4), (4, 1), (4, 2), (4, 3), (4, 4)]
Run Code Online (Sandbox Code Playgroud)
然后我获取了生成的每个元组的元素总和:
sum_tuple_combinations = [2, 3, 4, 5, 3, 4, 5, 6, 4, 5, 6, 7, 5, 6, 7, 8]
Run Code Online (Sandbox Code Playgroud)
现在我需要帮助计算元素总和为5的元素的乘积.所以对于这个例子,它将是元组(2,3),(3,2),(1,4)和(4, 1)哪会给我
[6,6,4,4]
Run Code Online (Sandbox Code Playgroud)
我将如何在Python上编写代码?
这是我到目前为止所做的:
import itertools
x = [1,2,3,4]
combinations= [p for p in itertools.product(x, repeat=2)]
print(combinations)
sum_of_combinations = map(sum, combinations)
print(sum_of_combinations)
#product_of_combinations = …Run Code Online (Sandbox Code Playgroud)