小编Bob*_*obo的帖子

使用word-cloud提高分辨率并删除空边框

我正在使用带有一些txt文件的文字云.如果我想1)增加分辨率和2)删除空边框,我如何更改此示例.

#!/usr/bin/env python2
"""
Minimal Example
===============
Generating a square wordcloud from the US constitution using default arguments.
"""

from os import path
import matplotlib.pyplot as plt
from wordcloud import WordCloud

d = path.dirname(__file__)

# Read the whole text.
text = open(path.join(d, 'constitution.txt')).read()
wordcloud = WordCloud().generate(text)
# Open a plot of the generated image.
plt.imshow(wordcloud)
plt.axis("off")
plt.show()
Run Code Online (Sandbox Code Playgroud)

python matplotlib word-cloud

22
推荐指数
2
解决办法
1万
查看次数

使用numpy数组修改pandas数据帧值

我正在尝试使用numpy数组[相同大小]修改pandas数据帧的values字段.这样的事情不起作用

import pandas as pd
# create 2d numpy array, called arr
df = pd.DataFrame(arr, columns=some_list_of_names)
df.values = myfunction(arr)
Run Code Online (Sandbox Code Playgroud)

任何替代品?

python numpy pandas

6
推荐指数
1
解决办法
1万
查看次数

'charmap'编解码器无法编码字符

我正在使用tweepy并在屏幕上打印推文消息时出现此错误(Windows).

#!/usr/bin/env python

from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
import json

#consumer key, consumer secret, access token, access secret.
ckey = 'xyz'
csecret = 'xyz'
atoken = 'xyz'
asecret = 'xyz'


class Listener(StreamListener):

    def on_data(self, data):
        print json.loads(data)['text']
        return True

    def on_error(self, status):
        print status


auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)

twitterStream = Stream(auth, Listener())
twitterStream.filter(track=['#hash1', '#hash2'], languages=['en'])   
Run Code Online (Sandbox Code Playgroud)
> Traceback (most recent call last):   File
> "C:....twitterSentiment.py",
> line 34, in <module>
>     twitterStream.filter(track=['#hash1', …
Run Code Online (Sandbox Code Playgroud)

python twitter tweepy

3
推荐指数
1
解决办法
4061
查看次数

用平均值替换字典值列表

我有一本字典,比如说mydict:

key1: list1
key2: list2
key3: list3
Run Code Online (Sandbox Code Playgroud)

什么是用平均值替换列表(值)的pythonic方法(避免循环)?

python dictionary

0
推荐指数
1
解决办法
269
查看次数

标签 统计

python ×4

dictionary ×1

matplotlib ×1

numpy ×1

pandas ×1

tweepy ×1

twitter ×1

word-cloud ×1