我需要动态更改我的语言应用程序。我有以下路线配置:
'route' => '/[:lang[/:controller[/:action[/:id]]]][[/page/:page]]',
'defaults' => array(
'lang' => 'en',
),
Run Code Online (Sandbox Code Playgroud)
是否可以从我的控制器或我的 Module.php(onBootstrap 函数)更改参数“lang”。我不知道我是否可以使用 globale 变量或类似的东西。
'defaults' => array(
'lang' => $my_variable,
),
Run Code Online (Sandbox Code Playgroud)
如果可能,我该如何改变它?
感谢您的帮助!
我有以下一段Swift代码连接到我的iOS模拟器中的Twitter帐户.
我的呼叫requestAccessToAccountsWithType被授予,但ACAccountStore.accountsWithAccountType返回一个空列表.
我错过了什么?
let accountStore = ACAccountStore()
let twitterAccountType = accountStore.accountTypeWithAccountTypeIdentifier(ACAccountTypeIdentifierTwitter)
accountStore.requestAccessToAccountsWithType(twitterAccountType, options: nil) { (granted, error) in
if granted {
print("requestAccessToAccountsWithType for \(twitterAccountType) is granted\n")
let accounts = accountStore.accountsWithAccountType(twitterAccountType)
print("accountsWithAccountType returns \(accounts.count) ")
} else {
let error = "Access to Twitter was not granted."
self.log(error)
handler(error)
}
}
Run Code Online (Sandbox Code Playgroud)
requestAccessToAccountsWithType for Twitter(com.apple.twitter)被授予accountsWithAccountType返回0
like我正在尝试在一个列上与另一个列一起使用该函数。可以Column在like函数内部使用吗?
示例代码:
df['col1'].like(concat('%',df2['col2'], '%'))
Run Code Online (Sandbox Code Playgroud)
错误日志:
py4j.Py4JException: py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:318) 处不存在类似([class org.apache.spark.sql.Column]) 的方法 (ReflectionEngine.java) :326)在py4j.Gateway.invoke(Gateway.java:274)在py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)在py4j.commands.CallCommand.execute(CallCommand.java:79)在py4j.GatewayConnection .run(GatewayConnection.java:214) 在 java.lang.Thread.run(Thread.java:748)
我有一个csv包含这样数据的文件
ID|Arr_of_Str
1|["ABC DEF"]
2|["PQR", "ABC DEF"]
Run Code Online (Sandbox Code Playgroud)
我想读取这个.csv文件,但是当我使用时sqlContext.read.load,它将它作为字符串读取
当前的:
df.printSchema()
root
|-- ID: integer (nullable = true)
|-- Arr_of_Str: string (nullable = true)
Run Code Online (Sandbox Code Playgroud)
预期的:
df.printSchema()
root
|-- ID: integer (nullable = true)
|-- Arr_of_Str: array (nullable = true)
|-- element: string (containsNull = true)
Run Code Online (Sandbox Code Playgroud)
如何将字符串转换为字符串数组?
我有一个包含 2 列的数据框:account_id并且email_address,现在我想再添加一列updated_email_address,我在该列上调用一些函数email_address来获取updated_email_address. 这是我的代码:
def update_email(email):
print("== email to be updated: " + email)
today = datetime.date.today()
updated = substring(email, -8, 8) + str(today.strftime('%m')) + str(today.strftime('%d')) + "_updated"
return updated
df.withColumn('updated_email_address', update_email(df.email_address))
Run Code Online (Sandbox Code Playgroud)
但结果显示updated_email_address列为空:
+---------------+--------------+---------------------+
|account_id |email_address |updated_email_address|
+---------------+--------------+---------------------+
|123456gd7tuhha |abc@test.com |null |
|djasevneuagsj1 |cde@test.com |null |
+---------------+--------------+---------------+
Run Code Online (Sandbox Code Playgroud)
updated_email在它打印出来的函数内部:
Column<b'(email_address + == email to be udpated: )'>
Run Code Online (Sandbox Code Playgroud)
它还将 df 的列数据类型显示为:
dfData:pyspark.sql.dataframe.DataFrame
account_id:string
email_address:string
updated_email_address:double
Run Code Online (Sandbox Code Playgroud)
为什么updated_email_address列类型是double?
user-defined-functions apache-spark apache-spark-sql pyspark
我有一个使用 spark-xml 包转换为数据帧的 XML 文件。数据框具有以下结构:
root
|-- results: struct (nullable = true)
| |-- result: struct (nullable = true)
| | |-- categories: struct (nullable = true)
| | | |-- category: array (nullable = true)
| | | | |-- element: struct (containsNull = true)
| | | | | |-- value: string (nullable = true)
Run Code Online (Sandbox Code Playgroud)
如果我选择类别列(可能在类别下多次出现):
df.select((col('results.result.categories.category')).alias("result_categories"))
Run Code Online (Sandbox Code Playgroud)
对于一个记录,结果看起来像
[[result1], [result2]]
Run Code Online (Sandbox Code Playgroud)
我试图压平结果:
[result1, result2]
Run Code Online (Sandbox Code Playgroud)
当我使用 flatten 函数时,我收到一条错误消息:
df.select(flatten(col('results.result.categories.category')).alias("Hits_Category"))
cannot resolve 'flatten(`results`.`result`.`categories`.`category`)' due to data type mismatch: The argument should …Run Code Online (Sandbox Code Playgroud) 我想拆分一列中的所有数字。
数字: 123456789012
成为 123-4567890-12
-所以我想在位置 4 和 10 处添加。
我不想创建新专栏
我对 pyspark 比较陌生。我想生成一个数据框列,其日期在两个给定日期(常量)之间,并将该列添加到现有数据框。有效的方法是什么?
我尝试了这个但没有成功:
df_add_column = df.withColumn("repeat", expr("split(repeat(',', diffDays), ',')")).select("*", posexplode("repeat").alias('DATE', "val")) .drop("repeat", "val", "diffDays").withColumn('DATE', expr("date_add('2018-01-01', 'DATE')"))
Run Code Online (Sandbox Code Playgroud) 这是我当前的数据集:
from pyspark.sql import Window
import pyspark.sql.functions as psf
df = spark.createDataFrame([("2","1",1),
("3","2",2)],
schema = StructType([StructField("Data", StringType()),
StructField("Source",StringType()),
StructField("Date", IntegerType())]))
display(df.withColumn("Result",psf.collect_set("Data").over(Window.partitionBy("Source").orderBy("Date"))))
Run Code Online (Sandbox Code Playgroud)
输出:
| 数据 | 来源 | 日期 | 结果 |
|---|---|---|---|
| 2 | 1 | 1 | [“2”] |
| 3 | 1 | 2 | [“2”,“3”] |
为什么在窗口上使用collect_set函数时,3列的第一行中缺少值?Resultordered
我也尝试过使用collect_list,但得到了相同的结果。
我想要的输出是:
| 数据 | 来源 | 日期 | 结果 |
|---|---|---|---|
| 2 | 1 | 1 | [“2”,“3”] |
| 3 | 1 | 2 | [“2”,“3”] |
其中值的顺序Result被保留 - 第一个是 where Date = 1,第二个是Date = 2
如果我尝试这样做,我会收到编译器错误
df.filter($"foo" == lit(0))
Run Code Online (Sandbox Code Playgroud)
忘记了我在 Spark 中需要一个三等号。
但是,如果我这样做,我会得到错误的答案,但没有错误:
df.filter($"foo".between(baz, quux) || $"foo" == lit(0))
Run Code Online (Sandbox Code Playgroud)
有人可以解释为什么编译时检查在第一种情况下对我有帮助,但在第二种情况下却没有帮助吗?
apache-spark ×8
pyspark ×7
dataframe ×1
ios ×1
python ×1
scala ×1
split ×1
swift ×1
zend-route ×1