小编red*_*vil的帖子

删除非ASCII字符并用Pandas数据帧中的空格替换

我一直试图解决这个问题.我试图从DB_user列中删除非ASCII字符并尝试用空格替换它们.但我不断收到一些错误.这就是我的数据框的外观:


+-----------------------------------------------------------
|      DB_user                            source   count  |                                             
+-----------------------------------------------------------
| ???/"Ò|Z?)?]??C %??J                      A        10   |                                       
| ?D$ZGU   ;@D??_???T(?)                    B         3   |                                       
| ?Q`H??M'?Y??KTK$?ً???ЩJL4??*?_??        C         2   |                                        
+-----------------------------------------------------------

我正在使用这个函数,这是我在研究SO上的问题时遇到的.

def filter_func(string):
   for i in range(0,len(string)):


      if (ord(string[i])< 32 or ord(string[i])>126
           break

      return ''

And then using the apply function:

df['DB_user'] = df.apply(filter_func,axis=1)
Run Code Online (Sandbox Code Playgroud)

我一直收到错误:


'ord() expected a character, but string of length 66 found', u'occurred at index 2'

但是,我想通过在filter_func函数中使用循环,我通过在'ord'中输入char来处理这个问题.因此,当它命中非ASCII字符时,它应该被空格替换.

有人可以帮帮我吗?

谢谢!

python string character-encoding pandas

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

Streamparse wordcount示例

我一直想使用Apache Storm从Kafka流式传输.我对Python更熟悉,所以我决定使用streamparse(https://github.com/Parsely/streamparse).单词计数示例是介绍性示例.我一直试图让它在我的本地机器上工作.我安装了以下版本的JDK,lein和storm:

Leiningen 2.6.1 on Java 1.8.0_73 Java HotSpot(TM) 64-Bit Server VM

按照streamparse之后运行以下步骤:

sparse quick start wordcount
cd wordcount
sparse run

我收到以下错误:


Retrieving org/apache/storm/storm-core/0.10.1/storm-core-0.10.1.pom from central
Retrieving org/apache/storm/storm/0.10.1/storm-0.10.1.pom from central
Retrieving org/apache/storm/storm-core/0.10.1/storm-core-0.10.1.jar from central
Could not transfer artifact com.parsely:streamparse:pom:0.0.4-SNAPSHOT from/to clojars (https://clojars.org/repo/): sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Could not transfer artifact clojure-complete:clojure-complete:pom:0.2.4 from/to clojars (https://clojars.org/repo/): sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to …

apache-kafka apache-storm streamparse

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

kafka-python中的多处理

我一直在使用python-kaka模块从kafka经纪人那里消费.我希望同时使用'x'个分区的相同主题.文档包含:

# Use multiple consumers in parallel w/ 0.9 kafka brokers
# typically you would run each on a different server / process / CPU
 consumer1 = KafkaConsumer('my-topic',
                      group_id='my-group',
                      bootstrap_servers='my.server.com')
  consumer2 = KafkaConsumer('my-topic',
                      group_id='my-group',
                      bootstrap_servers='my.server.com')
Run Code Online (Sandbox Code Playgroud)

这是否意味着我可以为我生成的每个进程创建一个单独的使用者?此外,consumer1和consumer2消费的消息是否会重叠?

谢谢

apache-kafka kafka-consumer-api kafka-python

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

Google pub-sub:计算特定订阅中的队列大小

我已经使用Google API处理Google pub-sub已有一段时间了。我想收集一些指标,特别是:

(1)个num_undelivered_messages(2个)num_outstanding_messages

我无权访问stackdriver帐户,我希望通过API获取指标。

我查看了以下页面:https ://cloud.google.com/monitoring/demos/,发现只有三个API可用:MonitoredResourceDescriptors.list,metricDescriptors.list和timeSeries.list

我不确定如何使用上述任何方法?有人可以帮我吗?

相关的SO问题是:Google PubSub-主题中的邮件计数

谢谢!

python publish-subscribe google-cloud-platform

5
推荐指数
0
解决办法
352
查看次数

访问 Google Cloud 上的 MongoDB 实例

我使用点击部署功能在 Google 云上设置了一个 MongoDB 实例。我一直在尝试使用命令行从另一个 Ubuntu GCP 实例连接到服务器。然而,我似乎不能。

我添加了一条防火墙规则以允许我的 MongoDB 实例侦听端口 27017。我使用了指令

gcloud 计算防火墙规则创建 default-allow-mongo \
     --允许 TCP:27017 \
     --源范围0.0.0.0/0 \
     --目标标签 mongodb \
     --description “允许 mongodb 访问所有 IP”

按照Google Cloud Mongo DB external ip notconnecting中的指示,我使用以下命令进行了检查

netstat -an | grep -我听| grep TCP

我得到了结果

tcp 0 0 0.0.0.0:27017 0.0.0.0:* 听

我还更改了 MongoDB 实例上的 mongod.conf 文件。我已将 GCP 实例的内部 IP 添加到bindIP。

这是我用来连接 MongoDB 客户端的代码:

client =  MongoClient('mongodb://username:password@X.X.X.X:27017')
# X.X.X.X = external IP of mongoDB instance

mydb = client['test2']  
posts = …
Run Code Online (Sandbox Code Playgroud)

mongodb google-cloud-platform

4
推荐指数
1
解决办法
6555
查看次数

使用 Dataframe.plot 函数在 pandas 时间序列上添加任意点

我一直在尝试使用 pandas dataframe 绘图函数绘制一些时间序列图。我试图在图上的某些任意点添加标记以显示异常点。我使用的代码:

df1 = pd.DataFrame({'Entropy Values' : MeanValues}, index=DateRange)
df1.plot(linestyle = '-')
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我有一个需要添加标记的日期列表。例如:

Dates = ['15:45:00', '15:50:00', '15:55:00', '16:00:00']
Run Code Online (Sandbox Code Playgroud)

我查看了这个链接matplotlib: Setmarkers for individual point on a line。DF.plot 有类似的功能吗?

我真的很感谢你的帮助。谢谢!

time-series pandas

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