我有一个问题,我从一些数据库图像中收到大量直方图。这些直方图表示为向量 (0...255),我必须识别并使用双峰直方图。
是否有一个公式可以自动识别哪些直方图是双峰的,哪些不是?由于它们是数字向量,我可以使用编程语言(Java/C#)来处理它。
文献中有没有软件识别双峰直方图的标准?
以下是我正在使用的直方图和格式输入的 3 个示例。每个直方图都是一个具有 256 (0...255) 个位置的向量。
Histogram 1
8029, 41, 82, 177, 135, 255, 315, 591, 949, 456, 499, 688, 446, 733, 712, 1595, 2633, 3945, 6134, 9755, 9236, 11911, 11888, 9450, 13119, 8819, 5991, 4399, 6745, 2017, 3747, 1777, 2946, 1623, 2151, 454, 3015, 3176, 2211, 1080, 391, 580, 750, 473, 10424, 334, 559, 621, 340, 2794, 1094, 5274, 2822, 204, 389, 728, 268, 15, 1060, 58, 113, 2728, 52, 3166, 11, 103, 522, 107, …Run Code Online (Sandbox Code Playgroud) 我想创建一个包含200个不同值的一百万个键的字符串:
N = 1000000
uniques_keys = [pd.core.common.rands(3) for i in range(200)]
keys = [random.choice(uniques_keys) for i in range(N)]
Run Code Online (Sandbox Code Playgroud)
但是,出现以下错误
In [250]:import pandas as pd
In [251]:pd.core.common.rands(3)
Traceback (most recent call last):
File "<ipython-input-251-31d12e0a07e7>", line 1, in <module>
pd.core.common.rands(3)
AttributeError: module 'pandas.core.common' has no attribute 'rands'
Run Code Online (Sandbox Code Playgroud)
我使用的熊猫版本为0.18.0。
我想在这里将这个SO主题修改为每小时三个小时.我有一个分钟分辨率的事件数据库.我需要每小时三次对它们进行分组,并提取该分组的计数.
理想情况下,输出看起来像下面的表:
3hourly count
0 10
3 3
6 5
9 2
...
Run Code Online (Sandbox Code Playgroud) 我有一个.csv文件,其中包含以下格式的城市,纬度和经度数据:
CITY|LATITUDE|LONGITUDE
A|40.745392|-73.978364
B|42.562786|-114.460503
C|37.227928|-77.401924
D|41.245708|-75.881241
E|41.308273|-72.927887
Run Code Online (Sandbox Code Playgroud)
我需要以下面的格式创建一个距离矩阵(请忽略虚拟值):
A B C D E
A 0.000000 6.000000 5.744563 6.082763 5.656854
B 6.000000 0.000000 6.082763 5.385165 5.477226
C 1.744563 6.082763 0.000000 6.000000 5.385165
D 6.082763 5.385165 6.000000 0.000000 5.385165
E 5.656854 5.477226 5.385165 5.385165 0.000000
Run Code Online (Sandbox Code Playgroud)
我已将数据加载到pandas数据框中,并创建了一个交叉连接,如下所示:
import pandas as pd
df_A = pd.read_csv('lat_lon.csv', delimiter='|', encoding="utf-8-sig")
df_B = df_A
df_A['key'] = 1
df_B['key'] = 1
df_C = pd.merge(df_A, df_B, on='key')
Run Code Online (Sandbox Code Playgroud)
我有我试图分组的数据框,它看起来像这样
Cust_ID Store_ID month lst_buy_dt1 purchase_amt
1 20 10 2015-10-07 100
1 20 10 2015-10-09 200
1 20 10 2015-10-20 100
Run Code Online (Sandbox Code Playgroud)
我需要的最大的ls_buy_dt和最大或购买金额为每个cust_ID,Store_ID在不同的数据帧每个月组合。示例输出:
Cust_ID Stored_ID month max_lst_buy_dt tot_purchase_amt
1 20 10 2015-10-20 400
Run Code Online (Sandbox Code Playgroud)
我的代码在下面。
aggregations = {
'lst_buy_dt1': { # Get the max purchase date across all purchases in a month
'max_lst_buy_dt': 'max',
},
'purchase_amt': { # Sum the purchases
'tot_purchase': 'sum', # Find the max, call the result "max_date"
}
}
grouped_at_Cust=metro_sales.groupby(['cust_id','store_id','month']).agg(aggregations).reset_index()
Run Code Online (Sandbox Code Playgroud)
我能够获得正确的聚合。但是,数据框在列中包含一个我无法删除的附加索引。无法显示,但这是结果
list(grouped_at_Cust.columns.values) …Run Code Online (Sandbox Code Playgroud) 我有每15秒一次的数据。但是,缺少一些值。这些没有用NaN标记,但是根本不存在。如何填写这些值?
我已经尝试过重新采样,但这也改变了我的原始数据。所以,为什么这行不通:
a=pd.Series([1.,3.,4.,3.,5.],['2016-05-25 00:00:35','2016-05-25 00:00:50','2016-05-25 00:01:05','2016-05-25 00:01:35','2016-05-25 00:02:05'])
a.index=pd.to_datetime(a.index)
a.resample('15S').mean()
In [368]: a
Out[368]:
2016-05-25 00:00:35 1.0
2016-05-25 00:00:50 3.0
2016-05-25 00:01:05 4.0
2016-05-25 00:01:35 3.0
2016-05-25 00:02:05 5.0
dtype: float64
Run Code Online (Sandbox Code Playgroud)
它向我展示了这一点:
2016-05-25 00:00:30 1.0
2016-05-25 00:00:45 3.0
2016-05-25 00:01:00 4.0
2016-05-25 00:01:15 NaN
2016-05-25 00:01:30 3.0
2016-05-25 00:01:45 NaN
2016-05-25 00:02:00 5.0
Freq: 15S, dtype: float64
Run Code Online (Sandbox Code Playgroud)
因此,我不再拥有00:35或00:50的值。
对于我最初的较大数据集,我还最终在重采样数据的末尾看到了许多大的NaN值。
我想将15s的数据重新采样到15s,所以每当在特定时间内没有数据存在时,都应该使用其周围的值的平均值来填充它。有没有办法做到这一点?
另外,为什么我重新采样时时间基准会改变?我的原始数据始于00:00:35,重新采样后始于00:30?好像它偏移了5秒。
在我的示例数据中,它应该做的所有事情都是在00:01:50创建一个附加数据条目。
编辑
我意识到我的数据比我想象的要复杂一些。实际上,“基础”在其中发生了部分变化。如果我使用下面的解决方案,则它适用于部分数据,但是值停止更改。例如:
a = pd.Series([1.,3.,4.,3.,5.,6.,7.,8.], ['2016-05-25 00:00:35','2016-05-25 00:00:50','2016-05-25 00:01:05','2016-05-25 00:01:35','2016-05-25 00:02:05','2016-05-25 00:03:00','2016-05-25 00:04:00','2016-05-25 00:06:00'])
In [79]: a
Out[79]: …Run Code Online (Sandbox Code Playgroud) 我在 B 列中有 100 行,但我只想找到 99 行的最大值。
如果我使用下面的代码,它会从 100 行而不是 99 行返回最大值:
print(df1['noc'].max(axis=0))
Run Code Online (Sandbox Code Playgroud) 我有4列的时间序列数据,我想GROUPBY列FisherID,DateFishing并且Total_Catch,总结列Weight.此外,我想Total_catch在列重量中减去列中的值,其结果将保留在名为的新列中DIFF.而且,我想在列中DIFF显示高于的值0.1.
这是我的代码.
df["DIFF"]=df.groupby(["FisherID", "DateFishing", "Total_Catch"]) ["Weight"].sum()-["Total_Catch"]>=0.1
Run Code Online (Sandbox Code Playgroud)
我的数据:
FisherID DateFishing Total_Catch Weight
1 24-Oct-11 0.9 0.2
1 24-Oct-11 0.9 0.264
1 24-Oct-11 0.9 0.37
2 25-Oct-11 0.7 0.144
2 27-Oct-11 8.2 0.084
2 27-Oct-11 8.2 0.45
3 27-Oct-11 8.2 0.61
3 27-Oct-11 8.2 7
3 29-Oct-11 0.64 0.184
Run Code Online (Sandbox Code Playgroud) 在索引列中,我有一个日期列表:
DatetimeIndex(['2010-12-31', '2011-01-02', '2011-01-03', '2011-01-29',
'2011-02-26', '2011-02-28', '2011-03-26', '2011-03-31',
'2011-04-01', '2011-04-03',
...
'2016-02-27', '2016-02-29', '2016-03-26', '2016-03-31',
'2016-04-01', '2016-04-03', '2016-04-30', '2016-05-31',
'2016-06-30', '2016-07-02'],
dtype='datetime64[ns]', length=123, freq=None)
Run Code Online (Sandbox Code Playgroud)
但是,我想过滤掉所有月份和日期等于12/31,3/31,6/30,9/30的那些,以获得该季度末的价值.
有没有好办法解决这个问题?
我有一个名为 'values' 的 pandas 列,其中包含相应的值10 15 36 95 99。我想从下一个值中减去每个值,以便获得以下格式:10 5 21 59 4
我试图使用循环遍历所有数据帧的 for 循环来解决这个问题,但这种方法很耗时。
for i in range(1,length_colulmn):
df['value'].iloc[i] = df['value'].iloc[i]-df['value'].iloc[i-1]
Run Code Online (Sandbox Code Playgroud)
数据帧功能是否有一种简单的方法可以快速解决这个问题?我们想要的输出如下:
['input']
11
15
22
27
36
69
77
['output']
11
4
7
5
9
33
8
Run Code Online (Sandbox Code Playgroud)