小编Arn*_*nab的帖子

如何检查我的RDD或数据帧是否被缓存?

我创建了一个数据帧说df1.我使用df1.cache()缓存了这个.如何检查是否已缓存?还有一种方法可以让我看到所有缓存的RDD或数据帧.

apache-spark

13
推荐指数
3
解决办法
8757
查看次数

Python 中的重复数据删除

在查看 Python 中用于记录重复数据删除的 Dedupe 库的示例时,我发现它在输出文件中创建了一个Cluster Id列,根据文档指示哪些记录相互引用。尽管我无法找出Cluster Id之间的任何关系以及这如何帮助查找重复记录。如果有人对此有所了解,请向我解释这一点。这是重复数据删除的代码。

# This can run either as a python2 or python3 code
from future.builtins import next

import os
import csv
import re
import logging
import optparse

import dedupe
from unidecode import  unidecode


input_file = 'data/csv_example_input_with_true_ids.csv'
output_file = 'data/csv_example_output1.csv'
settings_file = 'data/csv_example_learned_settings'
training_file = 'data/csv_example_training.json'

# Clean or process the data


def preProcess(column):

    try:
        column = column.decode('utf-8')
    except AttributeError:
        pass
    column = unidecode(column)
    column = re.sub(' +', ' ', column)
    column …
Run Code Online (Sandbox Code Playgroud)

python duplicates dedupeplugin python-dedupe

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

用 Cython 激发火花

我最近想Cython与 Spark一起使用,为此我遵循了以下参考

我写了下面提到的程序,但我得到了一个:

TypeError:
fib_mapper_cython() takes exactly 1 argument (0 given)
Run Code Online (Sandbox Code Playgroud)

spark-tools.py

def spark_cython(module, method):
    def wrapped(*args, **kwargs):
        global cython_function_
        try:
            return cython_function_(*args, **kwargs)
        except:
            import pyximport
            pyximport.install()
            cython_function_ = getattr(__import__(module), method)
        return cython_function_(*args, **kwargs)
    return wrapped()
Run Code Online (Sandbox Code Playgroud)

fib.pyx

def fib_mapper_cython(n):
    '''
     Return the first fibonnaci number > n.
    '''
    cdef int a = 0
    cdef int b = 0
    cdef int j = int(n)
    while b<j:
        a, b  = b, a+b
    return b, 1
Run Code Online (Sandbox Code Playgroud)

主文件

from …
Run Code Online (Sandbox Code Playgroud)

python cython pyspark

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

spark中首选哪些配置选项?

我想询问哪个配置选项在spark中具有优先权?它是配置文件还是我们在运行spark-submit shell时手动指定的选项?如果我的配置文件中有不同的执行程序内存选项,并且在运行spark-submit shell时指定了不同的值,该怎么办?

apache-spark

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

检查Scala中的数字是否为素数

我想检查一个数字是否为素数.我编写了以下代码,但它没有返回任何值:

 def isprime(x:Int) = {
     | if (x==1) false
     | else {
     | for (i <- 2 to x-1) {
     | if (x % i == 0) false
     | else true
     | }
     | }
     | }
Run Code Online (Sandbox Code Playgroud)

scala

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

使用reduceLeft代替scala中的foldLeft

我想确保我是否可以通过使用reduceLeft而不是foldLeft来实现这一目标.我在列表中搜索给定的数字

val included = List(46, 19, 92).foldLeft(false) { (a, i) =>
| if (a) a else (i == 19)
| }
included: Boolean = true
Run Code Online (Sandbox Code Playgroud)

但是我想用reduceLeft完成同样的工作,是否可能?

functional-programming scala fold

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

在列表列表中对元素进行分组

我有一些记录如下:

list1= [['corner grant and main reef road, new state area, springs', 'springs'],
     ['corner grant and main reef road, new state area, springs', 'palm springs'],
     ['corner grant and main reef road, new state area, springs', 'edenvale']]
Run Code Online (Sandbox Code Playgroud)

我希望我的记录看起来像这样:

list2= ['corner grant and main reef road, new state area, springs', 'springs | palm springs | edenvale']
Run Code Online (Sandbox Code Playgroud)

我编写了以下代码来完成此任务:

for i in range(len(list1)-1):
    if list1[i][0] == list1[i+1][0]:
        list2.append([list1[i][0], list1[i][1] + "|" + list1[i + 1][1]])
    else:
        pass
Run Code Online (Sandbox Code Playgroud)

如果我在列表中有两个元素并且是连续的条目,则它会起作用,但如果有超过2个项目且不连续,则会失败.任何人都可以指出一个合适的方法来实现这一目标.

python

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

按顺序附加到列表列表

我有两个列表列表:

my_list = [[1,2,3,4], [5,6,7,8]]
my_list2 = [['a', 'b', 'c'], ['d', 'e', 'f']]
Run Code Online (Sandbox Code Playgroud)

我希望我的输出看起来像这样:

my_list = [[1,2,3,4,'a','b','c'], [5,6,7,8,'d','e','f']]
Run Code Online (Sandbox Code Playgroud)

我编写了以下代码来执行此操作,但我最终在结果中获得了更多列表.

my_list = map(list, (zip(my_list, my_list2)))
Run Code Online (Sandbox Code Playgroud)

这会产生如下结果:

[[[1, 2, 3, 4], ['a', 'b', 'c']], [[5, 6, 7, 8], ['d', 'e', 'f']]]
Run Code Online (Sandbox Code Playgroud)

有没有办法可以删除冗余列表.谢谢

python list

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

在 python-docx 中更改段落格式

我正在尝试使用 Python 的 python-docx 模块更改多个段落的格式。

from docx import Document
from docx.shared import Pt
from docx.shared import Inches
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
from docx.enum.section import WD_ORIENTATION
from content import report_content, provinces, report_date, introduction, intro_content

alignment_dict = {'justify': WD_PARAGRAPH_ALIGNMENT.JUSTIFY,
                  'center': WD_PARAGRAPH_ALIGNMENT.CENTER,
                  'centre': WD_PARAGRAPH_ALIGNMENT.CENTER,
                  'right': WD_PARAGRAPH_ALIGNMENT.RIGHT,
                  'left': WD_PARAGRAPH_ALIGNMENT.LEFT}

orientation_dict = {'portrait': WD_ORIENTATION.PORTRAIT,
                    'landscape': WD_ORIENTATION.LANDSCAPE}

document = Document()


def change_orientation(orientation='portrait', set_left_margin=1.0, set_right_margin=1.0):
    section = document.sections[-1]
    new_width, new_height = section.page_height, section.page_width
    section.orientation = orientation_dict[orientation]
    section.page_width = new_width
    section.page_height = new_height
    section.left_margin = Inches(set_left_margin)
    section.right_margin = …
Run Code Online (Sandbox Code Playgroud)

python python-docx

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