Python 生成特定于趋势的数据
我有一个数据集(df1),它有两列Python 生成特定于趋势的数据,python,pandas,numpy,Python,Pandas,Numpy,我有一个数据集(df1),它有两列 F_Date B_Date 01/09/2019 02/08/2019 01/09/2019 03/08/2019 02/09/2019 03/08/2019 01/09/2019 04/08/2019 02/09/2019 04/08/2019 03/09/2019 04/08/2019 02/09/2019 05/08/2019 03/09/2019 05/08/2019 04/09/2019 05/08/2019 01/09/
F_Date B_Date
01/09/2019 02/08/2019
01/09/2019 03/08/2019
02/09/2019 03/08/2019
01/09/2019 04/08/2019
02/09/2019 04/08/2019
03/09/2019 04/08/2019
02/09/2019 05/08/2019
03/09/2019 05/08/2019
04/09/2019 05/08/2019
01/09/2019 06/08/2019
02/09/2019 06/08/2019
03/09/2019 06/08/2019
04/09/2019 06/08/2019
05/09/2019 06/08/2019
02/09/2019 07/08/2019
03/09/2019 07/08/2019
04/09/2019 07/08/2019
05/09/2019 07/08/2019
06/09/2019 07/08/2019
02/09/2019 08/08/2019
03/09/2019 08/08/2019
我希望生成一个新列值_1,以便:
F_Date B_Date value_1
01/09/2019 02/08/2019 5
01/09/2019 02/08/2019 15
01/09/2019 02/08/2019 30
我无法理解如何实现这两个步骤的趋势(增加)。有人能帮上忙吗?还有第二步
谢谢我可能错了,但你的问题在趋势生成的意义上相当模糊。然而,据我所知,你是这样做的: 第1步 使用以下方法生成具有趋势的新列值_1:
import numpy as np
min_y = 50
max_y = 5000
min_x = 1
# any number max_x can be chosen
# this number controls the shape of the logarithm, therefore the final distribution
max_x = 10
# generate (uniformly) and sort 30 random float x in [min_x, max_x)
x = np.sort(np.random.uniform(min_x, max_x, 30))
# get log(x), i.e. values in [log(min_x), log(max_x))
log_x = np.log(x)
# scale log(x) to the new range [min_y, max_y)
y = (max_y - min_y) * ((log_x - np.log(min_x)) / (np.log(max_x) - np.log(min_x))) + min_y
获得数据后,可以对另一个数据帧进行外部联接,然后在数据集中创建一个值为_1的数据帧
joined_df = pd.merge(df1,df2,on='F_Date')
我不确定你是否需要第二种趋势,更多细节会有所帮助