我有一系列文件,我想从每个文件中提取一个特定的数字.在每个文件中我都有这一行:
name, registration num
Run Code Online (Sandbox Code Playgroud)
并且正好有两行后面有注册号.我想从每个文件中提取这个数字.并把它作为一个字典的值.任何人都知道它是如何可能的?
我当前没有实际工作的代码如下所示:
matches=[]
for root, dirnames, filenames in os.walk('D:/Dataset2'):
for filename in fnmatch.filter(filenames, '*.txt'):
matches.append([root, filename])
filenames_list={}
for root,filename in matches:
filename_key = (os.path.join(filename).strip()).split('.',1)[0]
fullfilename = os.path.join(root, filename)
f= open(fullfilename, 'r')
for line in f:
if "<name, registration num'" in line:
key=filename_key
line+=2
val=line
Run Code Online (Sandbox Code Playgroud) 我有一个包含4个文本文件的文件夹.我想编写一个代码,用它来检查我文件夹中文件的大小,只打开那些大小相同的代码.任何人有任何想法?
我已经试过了
import os
d=os.stat('H:/My Documents/211').st_size
Run Code Online (Sandbox Code Playgroud) 我有这样的文本文件:
asn|prefix|ip|domain
25008|85.192.184.0/21|85.192.184.59|solusi-it.com
25008|85.192.184.0/21|85.192.184.59|samtimes.ru
131755|103.31.224.0/24|103.31.224.58|karosel-ind.com
131755|103.31.224.0/24|103.31.224.58|solusi-it.com
9318|1.232.0.0/13|1.234.91.168|solusi-it.com
9318|1.232.0.0/13|1.234.91.168|es350.co.kr
Run Code Online (Sandbox Code Playgroud)
有没有办法可以使用Linux Bash命令计算唯一域上的唯一ips数量并获得这样的结果?
domain|count_ip
solusi-it.com|3
samtimes.ru|1
karosel-ind.com|1
es350.co.kr|1
Run Code Online (Sandbox Code Playgroud) 我已经查看了其他似乎与我有同样问题的帖子,但我的问题还没有解决......
我正在尝试提取谷歌网页排名以获取域名列表,在本例中为"domain_list".以下是我正在使用的代码.我一直收到这个错误,无法找出它的根本原因.
import struct
import sys
import urllib
import urllib2
import httplib
import re
import xml.etree.ElementTree
domain_list = open('/data/personal/samaneh/test.txt','r')
class RankProvider(object):
"""Abstract class for obtaining the page rank (popularity)
from a provider such as Google or Alexa.
"""
def __init__(self, host, proxy=None, timeout=30):
"""Keyword arguments:
host -- toolbar host address
proxy -- address of proxy server. Default: None
timeout -- how long to wait for a response from the server.
Default: 30 (seconds)
"""
self._opener = urllib2.build_opener()
if proxy:
self._opener.add_handler(urllib2.ProxyHandler({"http": …
Run Code Online (Sandbox Code Playgroud) 这是我的数据集,包含两列 NS 和计数。
NS count
0 ns18.dnsdhs.com. 1494
1 ns0.relaix.net. 1835
2 ns2.techlineindia.com. 383
3 ns2.microwebsys.com. 1263
4 ns2.holy-grail-body-transformation-program.com. 1
5 ns2.chavano.com. 1
6 ns1.x10host.ml. 17
7 ns1.amwebaz.info. 48
8 ns2.guacirachocolates.com.br. 1
9 ns1.clicktodollars.com. 2
Run Code Online (Sandbox Code Playgroud)
现在我想通过绘制它来看看有多少 NS 具有相同的计数。我自己的猜测是我可以使用直方图来查看,但我不确定如何。任何人都可以帮忙吗?
我有一个像这样的数据帧:
col1,col2
Sam,NL
Man,NL-USA
ho,CA-CN
Run Code Online (Sandbox Code Playgroud)
我想选择第二列包含单词“NL”的行,这类似于 SQLlike
命令。有人知道 Python Pandas 中的类似命令吗?
我有一个散点图:
fig,ax = plt.subplots(figsize=(6,5),dpi=200)
ax.scatter(df1['id'],df1['resellers'],c='red',s=df1['ips']/80,label='AS Size = IPs seen in dnsdb')
ax.set_xticks([1,2,4,6,8,10,12,14,16,18,20])
ax.set_xlim(-1,22)
ax.legend(
scatterpoints=1,
loc='best',
ncol=1,
fontsize=12)
Run Code Online (Sandbox Code Playgroud)
我想知道如何将图例中气泡的形状和大小更改为矩形和更小的尺寸.有人可以帮忙吗?
我有一个像这样的词:
{1 : {'tp': 26, 'fp': 112},
2 : {'tp': 26, 'fp': 91},
3 : {'tp': 23, 'fp': 74}}
Run Code Online (Sandbox Code Playgroud)
我想转换成这样的数据帧:
t tp fp
1 26 112
2 26 91
3 23 74
Run Code Online (Sandbox Code Playgroud)
有人知道吗?
我有datafarme df:
id name number
1 sam 76
2 sam 8
2 peter 8
4 jack 2
Run Code Online (Sandbox Code Playgroud)
我想对“ id”列进行分组,并基于(名称,数字)对计算唯一值的数量?
id count(name-number)
1 1
2 2
4 1
Run Code Online (Sandbox Code Playgroud)
我已经尝试过了,但是不起作用:
df.groupby('id')[('number','name')].nunique().reset_index()
Run Code Online (Sandbox Code Playgroud) 注意:非现有的答案解决了我的问题
DF1:
asn used domain_used
1 9928 2594
2 2048 100
3 1792 170
4 57344 991
5 36864 1173
6 24576 194
7 26624 226
8 15360 584
9 65792 3003
10 1427968 32904
11 13312 266
12 28672 388
Run Code Online (Sandbox Code Playgroud)
我想基于domain_used列对此数据帧进行排序,如果"asn"位于前10行(排序时),则创建一个名为"top_bad"的新列为= 1.任何身体都能帮忙吗?