我需要删除西班牙语中的重音和来自不同数据集的其他语言的重音.
我已经在这篇文章提供的代码中做了一个函数,删除了特殊的重音符号.问题是函数很慢,因为它使用了UDF.我只是想知道我是否可以提高函数的性能以在更短的时间内获得结果,因为这对小型数据帧有好处,但对大型数据帧则不行.
提前致谢.
在这里代码,您将能够按照它呈现的方式运行它:
# Importing sql types
from pyspark.sql.types import StringType, IntegerType, StructType, StructField
from pyspark.sql.functions import udf, col
import unicodedata
# Building a simple dataframe:
schema = StructType([StructField("city", StringType(), True),
StructField("country", StringType(), True),
StructField("population", IntegerType(), True)])
countries = ['Venezuela', 'US@A', 'Brazil', 'Spain']
cities = ['Maracaibó', 'New York', ' São Paulo ', '~Madrid']
population = [37800000,19795791,12341418,6489162]
# Dataframe:
df = sqlContext.createDataFrame(list(zip(cities, countries, population)), schema=schema)
df.show()
class Test():
def __init__(self, df):
self.df = df
def clearAccents(self, …Run Code Online (Sandbox Code Playgroud) python unicode-normalization apache-spark apache-spark-sql pyspark
我正在apache-spark使用python在单个Dataframe上进行多次转换.
我编写了一些函数,以便更容易进行不同的转换.想象一下,我们有以下功能:
clearAccents(df,columns)
#lines that remove accents from dataframe with spark functions or
#udf
return df
Run Code Online (Sandbox Code Playgroud)
我使用这些函数"覆盖"dataframe变量,以保存每次函数返回时转换的新数据帧.我知道这不是一个好习惯,现在我看到了后果.
我注意到每次添加如下所示的行时,运行时间会更长:
# Step transformation 1:
df = function1(df,column)
# Step transformation 2.
df = function2(df, column)
Run Code Online (Sandbox Code Playgroud)
据我所知,Spark没有保存结果数据帧,但它保存了获取当前行中数据帧所需的所有操作.例如,当运行函数时,function1Spark只运行此函数,但是当运行function2Spark运行function1然后,function2.如果我真的需要只运行一个函数怎么办?
我尝试了df.cache(),df.persist()但我没有得到预期的结果.
我想以一种方式保存部分结果,这种方式不需要自开始以来只计算所有指令,只能从最后一个转换函数计算,而不会产生堆栈溢出错误.
设计师希望通过滑动手势获得以下动画。
可以看出,用户可以刷卡并查看每张卡有什么。同时,用户可以在屏幕右侧看到以下卡片和左侧最后一张卡片。此外,当用户移动滚动条时,卡片会改变它们的大小。
我已经使用过页面控件视图,但我不知道页面控件是否可以实现(这实际上是这篇文章的问题)。
另外,我已经尝试过使用 collectionView 但是当我滑动(实际上是水平滚动)时,滚动具有不舒服的惯性,而且我不知道如何制作动画。
在这个问题中,实现了滚动页面控件,但现在我只是想知道是否可以提供像 gif 这样的动画。
如果答案是肯定的,如果您能提供有关如何使这成为可能的提示,我将不胜感激。
提前致谢。
假设有一个日期框架,其中一列包含日期作为字符串.对于该假设,我们创建以下dataFrame作为示例:
# Importing sql types
from pyspark.sql.types import StringType, IntegerType, StructType, StructField, DoubleType, FloatType, DateType
from pyspark.sql.functions import date_format
import random
import time
def strTimeProp(start, end, format, prop):
stime = time.mktime(time.strptime(start, format)) # Parse a string representing a time according to a format
etime = time.mktime(time.strptime(end, format))
ptime = stime + prop * (etime - stime)
return time.strftime(format, time.localtime(ptime))
def randomDate(start, end, prop):
return strTimeProp(start, end, '%m-%d-%Y', prop)
# Creación de un dataframe de prueba:
schema = StructType(
[
StructField("dates1", …Run Code Online (Sandbox Code Playgroud)