小编use*_*755的帖子

如何在jq中的每次迭代中获取换行符

我有以下文件

[
  {
    "id": 1,
    "name": "Arthur",
    "age": "21"
  },
  {
    "id": 2,
    "name": "Richard",
    "age": "32"
  }
]
Run Code Online (Sandbox Code Playgroud)

要一起显示登录名和ID,我使用以下命令

$ jq '.[] | .name' test
"Arthur"
"Richard"
Run Code Online (Sandbox Code Playgroud)

但是当我把它放在一个shell脚本并尝试将它分配给一个变量时,整个输出显示在一行如下所示

#!/bin/bash

names=$(jq '.[] | .name' test)
echo $names

$ ./script.sh
"Arthur" "Richard"
Run Code Online (Sandbox Code Playgroud)

我想在每次迭代时打破,类似于它在命令行上的工作方式.

请帮忙

bash json newline output-formatting jq

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

在熊猫中并排显示两个数据框

我有两个数据帧,每个数据帧有10行,我正在尝试使用并排显示它们

print df, df2
Run Code Online (Sandbox Code Playgroud)

但是它给这样的输出

               Last       High   High_Perc
170     0.01324000 0.03822200 65.36026372
194     0.00029897 0.00052040 42.54996157
163     0.00033695 0.00058000 41.90517241
130     0.00176639 0.00282100 37.38426090
78      0.00003501 0.00005552 36.94164265
13      0.00009590 0.00014814 35.26393952
58      0.00002149 0.00003228 33.42627014
124     0.00009151 0.00013700 33.20437956
32      0.00059649 0.00089000 32.97865169         Last        Low    Low_Perc
170     0.01324000 0.01204685 65.36026372
194     0.00029897 0.00029000 42.54996157
163     0.00033695 0.00032270 41.90517241
130     0.00176639 0.00171874 37.38426090
78      0.00003501 0.00003450 36.94164265
13      0.00009590 0.00009200 35.26393952
58      0.00002149 0.00002140 33.42627014
124     0.00009151 0.00009000 33.20437956
32 …
Run Code Online (Sandbox Code Playgroud)

python dataframe pandas

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

列组中的子句

我有一个零售商店的数据,下面的列

col_1   qty_1   col_2    qty_2    col_3     qty_3
Green   5       Red        8      Yellow     10
Run Code Online (Sandbox Code Playgroud)

如果我想知道绿色的数量,那么我可以编写一个简单的查询,其中col_1 ='Green'。

但是我没有在col_1中得到绿色的颜色代码。它将在col_1,col_2和col_3之间不断改组,如下所示

col_1   qty_1   col_2    qty_2    col_3     qty_3
Green   5       Red        8      Yellow     10
Yellow  10      Green      7      Red        20
Run Code Online (Sandbox Code Playgroud)

我怎样才能有一个查询来提取可用的绿色数量而不每次都更改查询?

mysql sql select where-clause

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

配置tkinter小部件时出错:'NoneType'对象没有属性

我运行下面的代码,当我硬编码值时运行正常

from nsetools import Nse
nse = Nse()
with open('all_nse_stocks') as nse_stocks:
    for stock in nse_stocks:
        q = nse.get_quote('INFY')
        print q.get('open'), '\t', q.get('lastPrice'), '\t', q.get('dayHigh'), '\t', q.get('dayLow')
Run Code Online (Sandbox Code Playgroud)

看到我已经硬编码了值nse.get_quote('INFY')但是当我运行以下代码时,我收到以下错误:

from nsetools import Nse
nse = Nse()
with open('all_nse_stocks') as nse_stocks:
    for stock in nse_stocks:
        q = nse.get_quote(stock)
        print q.get('open'), '\t', q.get('lastPrice'), '\t', q.get('dayHigh'), '\t', q.get('dayLow')
Run Code Online (Sandbox Code Playgroud)

错误:

Traceback (most recent call last):
  File "test.py", line 6, in <module>
    print q.get('open'), '\t', q.get('lastPrice'), '\t', q.get('dayHigh'), '\t', q.get('dayLow')
AttributeError: 'NoneType' object has no attribute …
Run Code Online (Sandbox Code Playgroud)

python nonetype

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

在 PySpark 中将 StringType 列转换为 ArrayType

我有一个包含“EVENT_ID”列的数据框,其数据类型为字符串。我正在运行 FPGrowth 算法,但抛出以下错误

Py4JJavaError: An error occurred while calling o1711.fit. 
:java.lang.IllegalArgumentException: requirement failed: 
The input column must be array, but got string.
Run Code Online (Sandbox Code Playgroud)

列 EVENT_ID 有值

E_34503_Probe
E_35203_In
E_31901_Cbc
Run Code Online (Sandbox Code Playgroud)

我正在使用下面的代码将字符串列转换为数组类型

df2 = df.withColumn("EVENT_ID", df["EVENT_ID"].cast(types.ArrayType(types.StringType())))
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误

Py4JJavaError: An error occurred while calling o1874.withColumn.
: org.apache.spark.sql.AnalysisException: cannot resolve '`EVENT_ID`' due to data type mismatch: cannot cast string to array<string>;;
Run Code Online (Sandbox Code Playgroud)

如何将此列转换为数组类型或使用字符串类型运行 FPGrowth 算法?

python pattern-matching python-3.x pyspark fpgrowth

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