我有两个列表,一个参考和一个输入列表
Ref = [3, 2, 1, 12, 11, 10, 9, 8, 7, 6, 5, 4]
Input = [9, 5, 2, 3, 10, 4, 11, 8]
Run Code Online (Sandbox Code Playgroud)
我想按照 Ref 的顺序对输入列表进行排序。如果输入列表中缺少某个元素,它可以跳过并转到另一个元素。
因此排序的输入列表,基于参考列表将是这样的
Sorted_Input = [3, 2, 11, 10, 9, 8, 5, 4]
Run Code Online (Sandbox Code Playgroud) 我的 oracle linux 中安装了 python 2.6.6
我运行命令来安装包
pip install scipy
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误
[root@bigdatadev3 Downloads]# pip install scipy
DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of pip will drop support for Python 2.6
Collecting scipy
Using cached scipy-0.18.1.tar.gz
Building wheels for collected packages: scipy
Running setup.py bdist_wheel for scipy ... error
Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-zu4ibh/scipy/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpDdmSFupip-wheel- --python-tag …
Run Code Online (Sandbox Code Playgroud) 我有一个这样的数据集
temp <- structure(list(col_1 = c("", "P9603", "", "", "11040",
"80053"), col_2 = c("84484", "80061", "", "80061", "A0428", "85025"
), col_3 = c("V2632", "82310", "", "", "", "86357"), col_4 = c("J1170",
"84305", "62311", "80061", "", ""), col_5 = c("", "86708", "J0690",
"", "", "")), .Names = c("col_1", "col_2", "col_3", "col_4",
"col_5"), class = c("data.table", "data.frame"))
col_1 col_2 col_3 col_4 col_5
1: 84484 V2632 J1170
2: P9603 80061 82310 84305 86708
3: 62311 J0690
4: 80061 80061
5: 11040 A0428
6: …
Run Code Online (Sandbox Code Playgroud) 我有一个这样的数据框,只显示了两列,但是原始数据框中有很多列
data = [(("ID1", 3, 5)), (("ID2", 4, 12)), (("ID3", 8, 3))]
df = spark.createDataFrame(data, ["ID", "colA", "colB"])
df.show()
+---+----+----+
| ID|colA|colB|
+---+----+----+
|ID1| 3| 5|
|ID2| 4| 12|
|ID3| 8| 3|
+---+----+----+
Run Code Online (Sandbox Code Playgroud)
我想提取每行列的名称,它具有最大值。因此预期的输出是这样的
+---+----+----+-------+
| ID|colA|colB|Max_col|
+---+----+----+-------+
|ID1| 3| 5| colB|
|ID2| 4| 12| colB|
|ID3| 8| 3| colA|
+---+----+----+-------+
Run Code Online (Sandbox Code Playgroud)
如果出现平局,其中 colA 和 colB 具有相同的值,请选择第一列。
我怎样才能在 pyspark 中实现这一点
我有一个巨大的数据集(> 250 万)。一个小的子集看起来像这样(代码可重现)
temp <- data.frame(list(col1 = c("424", "560", "557"),
col2 = c("276", "427", "V46"),
col3 = c("780", "V45", "584"),
col4 = c("276", "V45", "995"),
col5 = c("428", "799", "427")))
> temp
col1 col2 col3 col4 col5
1 424 276 780 276 428
2 560 427 V45 V45 799
3 557 V46 584 995 427
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用此代码删除每行的重复项,并向左移动值
library(plyr)
temp <- apply(temp,1,function(x) unique(unlist(x)))
temp <- ldply(temp, rbind)
> temp
1 2 3 4 5
1 424 276 780 428 <NA>
2 560 …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 seaborn 打印条形图
plt.figure(figsize=(16, 6))
g = sns.barplot(x = 'A', y = 'B', data = df)
g.set_xticklabels(g.get_xticklabels(), rotation=90)
Run Code Online (Sandbox Code Playgroud)
但是,在实际绘图之前,有两个单元格会打印出类似这样的文本
out[3]: <Figure size 1152x432 with 0 Axes>
out[3]: [Text(0, 0, 'valueA'),
Text(0, 0, 'valueB'),
....
Text(0, 0, 'valueZ')]
<Actual BarPlot>
Run Code Online (Sandbox Code Playgroud)
如何在实际 BarPlot 之前抑制文本
我正在使用 ggpairs 并且在绘制矩阵时,我收到一个矩阵如下
如您所见,某些文本长度很大,因此无法完全看到文本。无论如何,我可以将文本包装起来,使其完全可见。
代码
ggpairs(df)
Run Code Online (Sandbox Code Playgroud)
我希望文本换行,以便可以看到这样的东西
我有一个包含超过 100 000 条记录的大型数据框,其中对值进行了排序
例如,考虑以下虚拟数据集
df <- data.frame(values = c(1,1,2,2,3,4,5,6,6,7))
Run Code Online (Sandbox Code Playgroud)
我想创建 3 组上述值(仅按顺序),以便每组的总和或多或少相同
因此,对于上述组,如果我决定将排序df
后的组按如下方式划分为3 组,则它们的总和将为
1. 1 + 1 + 2 +2 + 3 + 4 = 13
2. 5 + 6 = 11
3. 6 + 7 = 13
Run Code Online (Sandbox Code Playgroud)
如何在 R 中创建这种优化?任何逻辑?
我有一个这样的数据框
df = (pd.DataFrame({'ID': ['ID1', 'ID2', 'ID3'],
'colA': ['A', 'B', 'C'],
'colB': ['D', np.nan, 'E']}))
df
ID colA colB
0 ID1 A D
1 ID2 B NaN
2 ID3 C E
Run Code Online (Sandbox Code Playgroud)
我想合并这两列,但是如果 B 列是 NaN,则只保留 A 列。因此预期输出是
ID colA colB colC
0 ID1 A D A_D
1 ID2 B NaN B
2 ID3 C E C_E
Run Code Online (Sandbox Code Playgroud) 我有一个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)
如何将字符串转换为字符串数组?
python ×4
r ×4
dataframe ×3
apache-spark ×2
data.table ×2
pandas ×2
pyspark ×2
algorithm ×1
apply ×1
ggplot2 ×1
matplotlib ×1
nan ×1
optimization ×1
python-2.6 ×1
python-3.x ×1
seaborn ×1
sorting ×1