我已经提取了图像的forecolor,texture和edgemap值的base64字符串,我有一个包含以下结构的列表:
forecolor=AgCEAg4DUQQCBQQGARMBFQE1AmUB
edge=AfCAFg5iIATCPwTAEIiBFggBDw
forecolor=AgAsAQ0CJAMcDRgOGg8DHQYeBzYBPQ4-DU0ETgNtBm4CfQI
Run Code Online (Sandbox Code Playgroud)
我试图解码这些值,但我收到错误的填充错误,这是确切的错误:
Traceback (most recent call last):
File "ImageVectorData.py", line 44, in <module>
print "Decoded String: " + decoded.decode('base64', 'strict')
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/base64_codec.py", line 42, in base64_decode
output = base64.decodestring(input)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/base64.py", line 321, in decodestring
return binascii.a2b_base64(s)
binascii.Error: Incorrect padding
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
for item in value:
print "String before Split: " + item
if item.split("=")[0] == "forecolor":
decoded = (item.split("=")[1])
print "String to be decoded: " + decoded
print "Decoded String: " + decoded.decode('base64', 'strict')
Run Code Online (Sandbox Code Playgroud)
当第一个forecolor base64字符串被解码时,我也看到了一个有趣的输出:这是输出:
String …Run Code Online (Sandbox Code Playgroud) 我是jekyll的新手:
到目前为止,我已经完成了教程提到的内容:这就是我在_layout中的内容:post.html文件:
---
layout: default
---
<div class="post">
<h1>{{ page.title }}</h1>
<span class="post-date">{{ page.date | date_to_string }}</span>
{{ content }}
</div>
<div class="related">
<h2>Related Posts</h2>
<ul class="related-posts">
{% for post in site.related_posts limit:3 %}
<li>
<h3>
<a href="{{ post.url }}">
{{ post.title }}
<small>{{ post.date | date_to_string }}</small>
</a>
</h3>
</li>
{% endfor %}
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
我使用名称的md文件,2014-01-01-myNewPost.md我收到以下错误:
Generating... Invalid Date: '' is not a valid datetime.
Liquid Exception: exit in _layouts/post.html
Run Code Online (Sandbox Code Playgroud)
我似乎没有看到任何问题,但无法真正弄清楚为什么它不起作用.
我没有意识到Python设置函数实际上将字符串分成单个字符.我为Jaccard编写了python函数并使用了python intersection方法.我将两个集合传递给了这个方法,在将两个集合传递给我的jaccard函数之前,我在setring上使用了set函数.
例如:假设我有字符串NEW Fujifilm 16MP 5x Optical Zoom Point and Shoot CAMERA 2 7 screen.jpg我将调用set(NEW Fujifilm 16MP 5x Optical Zoom Point and Shoot CAMERA 2 7 screen.jpg),它将字符串分成字符.所以当我把它发送到jaccard函数交集时实际看字符交集而不是字对话.我该如何进行单词到单词的交集.
#implementing jaccard
def jaccard(a, b):
c = a.intersection(b)
return float(len(c)) / (len(a) + len(b) - len(c))
Run Code Online (Sandbox Code Playgroud)
如果我不在set我的字符串上调用函数,我NEW Fujifilm 16MP 5x Optical Zoom Point and Shoot CAMERA 2 7 screen.jpg会收到以下错误:
c = a.intersection(b)
AttributeError: 'str' object has no attribute 'intersection'
Run Code Online (Sandbox Code Playgroud)
而不是字符到字符的交集我想做单词到单词交叉并获得jaccard相似性.
在R中,有预先构建的函数来绘制随机森林模型的特征重要性.但是在python中这种方法似乎缺失了.我在搜索一个方法matplotlib.
model.feature_importances 给我以下:
array([ 2.32421835e-03, 7.21472336e-04, 2.70491223e-03,
3.34521084e-03, 4.19443238e-03, 1.50108737e-03,
3.29160540e-03, 4.82320256e-01, 3.14117333e-03])
Run Code Online (Sandbox Code Playgroud)
然后使用以下绘图功能:
>> pyplot.bar(range(len(model.feature_importances_)), model.feature_importances_)
>> pyplot.show()
Run Code Online (Sandbox Code Playgroud)
我得到了一个条形图,但我希望得到带有标签的条形图,同时重要性以有条理的方式水平显示.我也在探索seaborn,但无法找到方法.
我习惯macport,最近得到了一个新的mac book pro 10.8.4,我切换brew并试图安装python但我收到以下错误:
brew install python --universal --framework
Error: You must `brew link gdbm' before python can be installed
Run Code Online (Sandbox Code Playgroud)
我试图按照以下链接使用brew安装python,但它一直在说链接,我不明白. WebSite 1,webSite 2
以下是我收到的警告:
brew install readline sqlite gdbm
Warning: readline-6.2.4 already installed
Warning: sqlite-3.7.17 already installed
Warning: gdbm-1.10 already installed, it's just not linked
Run Code Online (Sandbox Code Playgroud)
除此之外,我试图将它链接到brew链接gdbm,但我得到以下权限问题:
file: /usr/local/Cellar/gdbm/1.10/include/gdbm.h
/usr/local/include is not writable. You should change its permissions.
Run Code Online (Sandbox Code Playgroud)
我查了/ usr/local/include并且它有写权限
drwxr-xr-x 29 root wheel 986 Mar 30 16:46 include ( I am not the root)
Run Code Online (Sandbox Code Playgroud)
我不是root用户,也没有root密码,但我确实在机器上有sudo权限.
目标:将搜索字符串传递给谷歌搜索并抓取网址,标题以及与网址标题一起发布的小描述.
我有以下代码,目前我的代码只提供前10个结果,这是一个页面的默认谷歌限制.我不确定如何在webscraping期间真正处理分页.此外,当我查看实际的页面结果和打印出来的内容时,存在差异.我也不确定解析span元素的最佳方法是什么.
到目前为止,我的跨度如下,我想删除<em>元素并连接其余的stings.最好的方法是什么?
<span class="st">The <em>Beautiful Soup</em> Theater Collective was founded in the summer of 2010 by its Artistic Director, Steven Carl McCasland. A continuation of a student group he <b>...</b><br /></span
Run Code Online (Sandbox Code Playgroud)
码:
from BeautifulSoup import BeautifulSoup
import urllib, urllib2
def google_scrape(query):
address = "http://www.google.com/search?q=%s&num=100&hl=en&start=0" % (urllib.quote_plus(query))
request = urllib2.Request(address, None, {'User-Agent':'Mosilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11'})
urlfile = urllib2.urlopen(request)
page = urlfile.read()
soup = BeautifulSoup(page)
linkdictionary = {}
for li …Run Code Online (Sandbox Code Playgroud) 我有以下数据框。数据框是通过读取 csv 文件构建的。它是一个很大的数据集,但出于这个问题的目的,我使用了数据集中的 15 行作为示例。
user_id contrib_count total_min_length group_space expert_level
0 23720 108 1112696 0 l-2
1 23720 13 442059 1 l-2
2 23720 12 32180 2 l-2
3 23720 2 20177 3 l-2
4 23720 1 1608 10 l-2
5 1265184 71 260186 0 l-G
6 1265184 10 3466 2 l-G
7 1265184 1 12081 4 l-G
8 513380 112 1049311 0 l-4
9 513380 1 97 1 l-4
10 513380 113 361980 2 l-4
11 513380 19 1198323 …Run Code Online (Sandbox Code Playgroud) 我查看了之前提出的大多数问题,但无法找到我的问题的答案:
我有以下data.frame
id year month score num_attempts
0 483625 2010 01 50 1
1 967799 2009 03 50 1
2 213473 2005 09 100 1
3 498110 2010 12 60 1
5 187243 2010 01 100 1
6 508311 2005 10 15 1
7 486688 2005 10 50 1
8 212550 2005 10 500 1
10 136701 2005 09 25 1
11 471651 2010 01 50 1
Run Code Online (Sandbox Code Playgroud)
我想获得以下数据框
year month sum_score sum_num_attempts
2009 03 50 1
2005 09 125 2 …Run Code Online (Sandbox Code Playgroud) 我在用 conda python 2.7
python --version
Python 2.7.12 :: Anaconda 2.4.1 (x86_64)
Run Code Online (Sandbox Code Playgroud)
我有休闲的方法来读取大的gzip文件:
df = pd.read_csv(os.path.join(filePath, fileName),
sep='|', compression = 'gzip', dtype='unicode', error_bad_lines=False)
Run Code Online (Sandbox Code Playgroud)
但是当我读取文件时,出现以下错误:
pandas.parser.CParserError: Error tokenizing data. C error: Calling read(nbytes) on source failed. Try engine='python'.
Segmentation fault: 11
Run Code Online (Sandbox Code Playgroud)
我阅读了所有现有的答案,但是其中大多数问题都有错误,例如其他列。我已经用error_bad_lines=False选项处理了。
我在这里有什么选择?
当我尝试解压缩文件时发现了一些有趣的东西:
gunzip -k myfile.txt.gz
gunzip: myfile.txt.gz: unexpected end of file
gunzip: myfile.txt.gz: uncompress failed
Run Code Online (Sandbox Code Playgroud) python ×8
pandas ×3
base64 ×1
dataframe ×1
decode ×1
group-by ×1
homebrew ×1
intersection ×1
jekyll ×1
matplotlib ×1
pivot-table ×1
ruby ×1
scrapy ×1
seaborn ×1
selenium ×1
set ×1
urllib ×1
web-crawler ×1
web-scraping ×1