小编mob*_*cdi的帖子

从 len 18000 的 Dask 数据帧中采样 n= 2000 会产生错误当“replace=False”时不能采用比总体更大的样本

我有一个从 csv 文件创建的 dask 数据框并len(daskdf)返回 18000 但是当ddSample = daskdf.sample(2000)我收到错误时

ValueError: Cannot take a larger sample than population when 'replace=False'
Run Code Online (Sandbox Code Playgroud)

如果数据框大于样本大小,我可以在不替换的情况下进行采样吗?

python dask

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

如何有效地将pos_tag_sents()应用于pandas数据帧

如果您希望POS标记存储在pandas数据帧中的文本列,每行1个句子,则SO上的大多数实现都使用apply方法

dfData['POSTags']= dfData['SourceText'].apply(
                 lamda row: [pos_tag(word_tokenize(row) for item in row])
Run Code Online (Sandbox Code Playgroud)

NLTK文档建议使用pos_tag_sents()来有效标记多个句子.

这是否适用于这个例子中,如果是将代码那样改变简单pso_tagpos_tag_sents或不NLTK意味着段落的文本来源

正如评论中所提到的那样,pos_tag_sents()目的是每次都减少负载的负载,但问题是如何做到这一点并仍然在pandas数据帧中产生一个列?

链接到示例数据集20kRows

python nltk pos-tagger python-3.x pandas

11
推荐指数
1
解决办法
4114
查看次数

如何在自动生成主标识符时使用selenium访问文本字段

我有一个HTML表格,每行输出一些数据,每行包含一个文本字段.我有一个单独的数据框,其中包含我需要输入到相关行的值,但我无法弄清楚如何获取正确的文本输入元素,因为名称不是唯一的.

我可以得到包含的元素,123456/1所以我可以找到包含我想要的PartA的行,但我无法弄清楚如何获取文本输入字段id ="VALUE.ENTER.SYSTEM.1-XY然后对应于该行..XY是一个数值,它根据数据行的数量而变化,我不能假设XY的特定值对应于我想要查找的值.

我不知道该行的完整@value,并且页面上列出的值一次限制为50只因为我没有找到它一次并不意味着它不会出现在后面的页面上.我需要找到表中的第一行,从中提取一个值然后如果我在另一个数据帧中有匹配,如果我这样做,我想在行的末尾向文本框添加一个值,然后继续下一行并重复extract,compare,submit步骤,直至用完了行

任何可靠的方法来定位python中的文本输入字段

title ="EnterValueHere"

我的守则

for row in rows:
    RowData = row.find_elements_by_tag_name("input")
    for cell in RowData:
        #Get the ID in question
        if "/" in cell.get_attribute("value"):
            TextToSplit =cell.get_attribute("value")
            PartA,PartB= str(TextToSplit).split("/")
            print(PartA)
Run Code Online (Sandbox Code Playgroud)

样本表

  <tr>
                <td class="tablesaw-cell-persist">
                  <input type="hidden" name="UNIQUE_ID.SYSTEM.01" value="12">
                  <input type="hidden" name="HEADER_ID.SYSTEM.01" value="">
                  123456/1<input type="hidden" name="CODE.SYSTEM.01" value="123456/1">
                  <span id="ANCHOR.SYSTEM.01"></span>
                </td>
                <td class="tablesaw-cell-persist">
                  BLOGGS JOE<input type="hidden" name="NAME.SYSTEM.01" value="JOE BLOGGS">
                </td>
                <td class="tablesaw-cell-persist">
                  1<input type="hidden" name="ATTEMPT.SYSTEM.01" value="1">
                </td>

                <td> …
Run Code Online (Sandbox Code Playgroud)

python-3.x selenium-webdriver

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

Google Compute Engine 启动脚本:启动时未运行

我试图在 GCE 上启动时让以下脚本在 CentOS 实例上运行。我在实例名称上设置了自定义元数据“启动脚本”,并将以下脚本作为值。

该脚本不会在启动、重启或运行 /usr/share/google/run-startup-scripts 时执行,但如果我在实例上本地创建它并在那里执行,则会执行

我错过了什么明显的东西?

#! /bin/bash
# Installs apache and a custom homepage
# 1234567 123456

#Get this servers name from the metadata server and use the header to authenticate
THIS_SERVER_NAME=$(curl http://metadata/computeMetadata/v1/instance/hostname -H "X-Google-Metadata-Request: True")
#Turn off IPtables firewall that comes installed
service iptables stop
#Install apache
yum install -y httpd
#start apache
service httpd start
#create custom default homepage for this server
cat <<EOF > /var/www/html/index.html
<html><body><h1>Hello World</h1>
<p>This is Server: $THIS_SERVER_NAME</p>
</body></html>
EOF
Run Code Online (Sandbox Code Playgroud)

startup google-compute-engine

5
推荐指数
1
解决办法
3462
查看次数

如何将Polyglot Detector功能应用于数据帧

假设我有一个名为列df.Text包含文本(多于1句),我想使用多种语言的Detector检测语言和值存储在一个新的列df['Text-Lang']我如何确保我还捕捉到其他细节,如codeconfidence

testEng ="This is English"
lang = Detector(testEng)
print(lang.language)
Run Code Online (Sandbox Code Playgroud)

回报

名称:英文代码:en confidence:94.0读取字节:1920

df['Text-Lang','Text-LangConfidence']= df.Text.apply(Detector)
Run Code Online (Sandbox Code Playgroud)

以..结束

AttributeError:'float'对象没有属性'encode',并且Detector无法可靠地检测语言.

我是否正确应用检测器功能或错误地存储输出?

python polyglot pandas

5
推荐指数
1
解决办法
690
查看次数

如何将具有大量列数的csv文件导入Apache Spark 2.0

我遇到了将多个小型csv文件导入250000 columns of float64到作为Google Dataproc集群运行的Apache Spark 2.0中的问题.有一些字符串列,但只对1作为类标签真正感兴趣.

当我在pyspark中运行以下内容时

csvdata = spark.read.csv("gs://[bucket]/csv/*.csv", header=True,mode="DROPMALFORMED")
Run Code Online (Sandbox Code Playgroud)

我得到了

get_return_value文件中的"/usr/lib/spark/python/lib/py4j-0.10.1-src.zip/py4j/protocol.py",第312行py4j.protocol.Py4JJavaError:调用o53.csv时发生错误.:com.univocity.parsers.common.TextParsingException:java.lang.ArrayIndexOutOfBoundsException - 20480 提示:处理可能已超过20480列的极限列数.使用settings.setMaxColumns(int)定义输入可以拥有的最大列数 确保配置正确,分隔符,引号和转义序列与您尝试解析的输入格式匹配解析器配置:CsvParserSettings:

  1. 在哪里/如何设置解析器的最大列以使用数据进行机器学习.
  2. 有没有更好的方法来摄取数据以用于Apache mllib?

这个问题指向定义要使用的数据帧的类,但是可以定义这么大的类而不必创建210,000个条目吗?

csv apache-spark pyspark apache-spark-mllib google-cloud-dataproc

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

使用格式运算符%将numpy RGB值数组转换为十六进制

关于这个SO 问题,使用格式化运算符将其应用于numpy数组的最佳方法是什么,其中数组的格式为下面给出的RGB值对应的格式

注意RGB值已经缩放为0到1,因此需要多次255来重新缩放

array([[ 0.40929448,  0.47071505,  0.27701891],
       [ 0.59383913,  0.60611158,  0.55329837],
       [ 0.4393785 ,  0.4276561 ,  0.34999225],
       [ 0.4159481 ,  0.4516056 ,  0.3026519 ],
       [ 0.54449997,  0.36963636,  0.4001209 ],
       [ 0.36970012,  0.3145826 ,  0.315974  ]])
Run Code Online (Sandbox Code Playgroud)

并且您想要每行的十六进制三元组

python format numpy colors

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

Pandas read_html 导致 TypeError

我正在使用 bs4 来解析一个 html 页面并提取一个表格,下面给出的示例表格,我试图将它加载到 Pandas 中,但是当我打电话时,pddataframe = pd.read_html(LOTable,skiprows=2, flavor=['bs4'])我得到下面列出的错误,但我可以打印由 bs4 美化的表格

有什么建议可以解决这个问题,而无需获取每个 td 并逐一读取?

样品表

<table cellpadding="5" cellspacing="0" class="borders" width="100%">
    <tr>
     <th colspan="2">
      Learning Outcomes
     </th>
    </tr>
    <tr>
     <td class="info" colspan="2">
      On successful completion of this module the learner will be able to:
     </td>
    </tr>
    <tr>
     <td style="width:10%;">
      LO1
     </td>
     <td>
      Demonstrate an awareness of the important role of Financial Accounting information as an input into the decision making process.
     </td>
    </tr>
    <tr>
     <td style="width:10%;">
      LO2
     </td> …
Run Code Online (Sandbox Code Playgroud)

python pandas

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

使用r和ggplot如何指定用于表示不同字符值的特定十六进制颜色/颜色值

假设is.character(MyColours) = TRUEMyColours包含许多十六进制颜色值.

我如何确保当我想使用ggplot绘图时,我可以确保MyColours [1]将始终用于表示"Ford",MyColour [3]将代表"Toyota",当我无法保证订单"Ford"时或"丰田"将出现在我用来绘制的观察中.

虽然下面的geo_bar示例很有用,但确实提醒我添加列名称,MyColours我希望绘制的行不是条形

    ggplot(MyData, aes(x = TimePeriod, y = CountOfItems, 
group = Account, color = scale_fill_manual(values = MyColours))) 
    + geom_line(size = 1) 
    + theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
Run Code Online (Sandbox Code Playgroud)

Aesthetics must either be length one, or the same length as the dataProblems:scale_fill_manual(values = MyColours)即使length(MyColours)等于,我也会得到错误length(unique(MyData$Account))

样本数据

dput(MyData)
structure(list(Account = structure(c(1L, 2L, 1L, 2L), .Label = c("Mazda RX4", 
"Toyota Corolla"), class = "factor"), CountOfItems = c(14, 120, …
Run Code Online (Sandbox Code Playgroud)

hex r colors ggplot2

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