UserWarning:布尔系列键将重新索引以匹配DataFrame索引 [英] UserWarning: Boolean Series key will be reindexed to match DataFrame index
问题描述
使用此语句时,这会在单个语句中显示多个警告:
When using this statement this shows multiple warning in a single statements:
Internaldfdeny=pd.DataFrame({'Count':Internaldf[Internaldf['Status']=='deny'][Internaldf['SrcIP']!="NA"][Internaldf['DstIP']!="NA"][Internaldf['TimeStamp']-Internaldf['TimeStamp'].iloc[0]<pd.tslib.Timedelta(minutes=30)].groupby(['DstPort','SrcIP']).size()}).reset_index().pivot_table('Count',['DstPort'],'SrcIP').fillna(0).to_sparse(fill_value=0)
警告是:
/home/lubuntu/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:1: UserWarning:布尔系列键将被重新索引以匹配DataFrame 指数. "启动IPython内核的入口点. /home/lubuntu/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:1: UserWarning:布尔系列键将被重新索引以匹配DataFrame 指数. "启动IPython内核的入口点. /home/lubuntu/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:1: FutureWarning:不建议使用pandas.tslib,并将在 未来版本. 您可以将Timedelta作为熊猫来访问. "启动IPython内核的入口点. /home/lubuntu/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:1: UserWarning:布尔系列键将被重新索引以匹配DataFrame 指数. "启动IPython内核的入口点.
/home/lubuntu/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:1: UserWarning: Boolean Series key will be reindexed to match DataFrame index. """Entry point for launching an IPython kernel. /home/lubuntu/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:1: UserWarning: Boolean Series key will be reindexed to match DataFrame index. """Entry point for launching an IPython kernel. /home/lubuntu/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:1: FutureWarning: pandas.tslib is deprecated and will be removed in a future version. You can access Timedelta as pandas.Timedelta """Entry point for launching an IPython kernel. /home/lubuntu/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:1: UserWarning: Boolean Series key will be reindexed to match DataFrame index. """Entry point for launching an IPython kernel.
我找不到任何其他旋转表的方法:
I couldn't find any other method of pivoting the table:
我检查了没有to_sparse(0),但它仍然显示它! 这是重要的警告吗? 我一直在忽略它. 我一直在用 Jupyter笔记本 Python v3.6 通过anaconda安装(如果有的话).
I had checked without to_sparse(0) but it still shows it! Is this an important warning? I have been neglecting it. I've been using Jupyter Notebook Python v3.6 Installed through anaconda if that at all is relevant.
Internaldf.head()
显示
TimeStamp SrcIP DstIP DstPort Status
0 2018-03-31 03:48:13.731929 192.168.52.43 166.62.28.228 80 close
1 2018-03-31 03:48:13.749007 10.208.23.136 96.45.33.73 8888 deny
2 2018-03-31 03:48:13.799235 10.208.2.56 14.142.64.16 8081 deny
3 2018-03-31 03:48:13.799235 10.208.35.193 13.75.119.102 443 close
4 2018-03-31 03:48:13.799235 10.208.2.70 10.208.3.255 137 deny
推荐答案
我认为需要:
m1 = Internaldf['Status']=='deny'
m2 = Internaldf['SrcIP']!="NA"
#if want check non NaNs
#m2 = Internaldf['SrcIP'].notnull()
m3 = Internaldf['DstIP']!="NA"
#if want check non NaNs
#m3 = Internaldf['DstIP'].notnull()
m4 = Internaldf['TimeStamp']-Internaldf['TimeStamp'].iloc[0] < pd.Timedelta(minutes=30)
#chain condition with & for AND or by | for OR, for column use reset_index
df=Internaldf[m1 & m2 & m3 & m4].groupby(['DstPort','SrcIP']).size().reset_index(name='Count')
Internaldfdeny=df.pivot_table('Count','DstPort','SrcIP').fillna(0).to_sparse(fill_value=0)
print (Internaldfdeny)
SrcIP 10.208.2.56 10.208.2.70 10.208.23.136
DstPort
137 0.0 1.0 0.0
8081 1.0 0.0 0.0
8888 0.0 0.0 1.0
这篇关于UserWarning:布尔系列键将重新索引以匹配DataFrame索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!