UserWarning:布尔系列键将重新索引以匹配 DataFrame 索引
UserWarning: Boolean Series key will be reindexed to match DataFrame index
使用此语句时,这会在单个语句中显示多个警告:
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: 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.
我找不到旋转 table 的任何其他方法:
我在没有 to_sparse(0) 的情况下进行了检查,但它仍然显示它!
这是一个重要的警告吗?
我一直忽略它。
我一直在用
木星笔记本
Python v3.6
如果完全相关,则通过 anaconda 安装。
编辑:
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
使用此语句时,这会在单个语句中显示多个警告:
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: 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.
我找不到旋转 table 的任何其他方法:
我在没有 to_sparse(0) 的情况下进行了检查,但它仍然显示它! 这是一个重要的警告吗? 我一直忽略它。 我一直在用 木星笔记本 Python v3.6 如果完全相关,则通过 anaconda 安装。
编辑:
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