我的目标是使用 Spark DataFrame 对分类列列表进行一次性编码。例如,与get_dummies()函数在Pandas.
该数据集bureau.csv最初取自 Kaggle 竞赛Home Credit Default Risk。这是我的条目表示例,比如说entryData,它被过滤的地方只有KEY = 100001。
# primary key
KEY = 'SK_ID_CURR'
data = spark.read.csv("bureau.csv", header=True, inferSchema=True)
# sample data from bureau.csv of 1716428 rows
entryData = data.select(columnList).where(F.col(KEY) == 100001).show()
print(entryData)
Run Code Online (Sandbox Code Playgroud)
+----------+-------------+---------------+---------------+
|SK_ID_CURR|CREDIT_ACTIVE|CREDIT_CURRENCY| CREDIT_TYPE|
+----------+-------------+---------------+---------------+
| 100001| Closed| currency 1|Consumer credit|
| 100001| Closed| currency 1|Consumer credit|
| 100001| Closed| currency 1|Consumer credit|
| 100001| Closed| currency 1|Consumer credit|
| 100001| Active| …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写 Node.js 脚本,该脚本使用serialportnpm 包来读取数据并将数据写入COM5串行端口,该串行端口使用 RS-232 电缆连接到设备。该设备会自动传输其拥有的数据。
要检索设备内部存储的数据,我需要首先uInt8向设备发送一个字节 0x80 ( ),并期望从设备接收 81 作为十六进制数字。其次,我需要发送另一个字节 0x81 ( uInt8),然后期望以行形式接收所有存储的数据(大约 130000 字节)。
无法仅通过两个字节一个接一个地检索整个存储的数据。与设备的通信只能通过字节来完成。
我尝试了以下代码:
import SerialPort from 'serialport';
const sp = new SerialPort.SerialPort({path: "COM5", baudRate: 115200});
const buff = Buffer.allocUnsafe(1);
buff.writeUInt8(0x80, 0);
sp.write(buff, function (err){
if (err){
return console.log("Error on write: ", err.message);
}
console.log("Port.write: ", buff);
});
sp.on('readable', function () {
var arr = new Uint8Array(sp._pool);
console.log('Data:', arr);
});
Run Code Online (Sandbox Code Playgroud)
运行我的脚本(使用node myScript.mjs)时,我看到以下内容:
PortWrite: <Buffer 80>
Data: …Run Code Online (Sandbox Code Playgroud) 我有一个data.txt文件,我想将其转换为data.json文件并打印前 2 个条目(data.txt包含 3 个唯一 ID)。
可以在这里data.txt公开找到(这是一个示例 - 原始文件包含 10000 个唯一的)。"linkedin_internal_id
我尝试了以下方法:
with open("data.txt", "r") as f:
content = f.read()
data = json.dumps(content, indent=3)
Run Code Online (Sandbox Code Playgroud)
此代码不会打印适当的JSON格式data.txt(它还包括\\)。另外,jupyter notebook由于文件太大,我的文件被堆积起来,为此,我想只打印前两个条目。
我有以下两个列表:
A = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
B = ['b', 'd', 'f', 'g']
Run Code Online (Sandbox Code Playgroud)
我想检查其中的元素B是否在Athen 0else 中1。预期的输出应该是这样的:
{'C': [0, 1, 0, 1, 0, 1, 1]}
Run Code Online (Sandbox Code Playgroud)
我尝试了以下但没有得到我所期望的。
{'C': [int(i == j) for j in A] for i in B}
Run Code Online (Sandbox Code Playgroud) 我试图scipy.special.rel_entr在GitHub Repo中查找函数的代码源,但找不到rel_entr函数定义。
我还尝试查看此代码:https://github.com/scipy/scipy/pull/6522/files#diff-0
我有以下元组列表。
lst =
[
('LexisNexis', ['IT Services and IT Consulting ', ' New York City, NY']),
('AbacusNext', ['IT Services and IT Consulting ', ' La Jolla, California']),
('Aderant', ['Software Development ', ' Atlanta, GA']),
('Anaqua', ['Software Development ', ' Boston, MA']),
('Thomson Reuters Elite', ['Software Development ', ' Eagan, Minnesota']),
('Litify', ['Software Development ', ' Brooklyn, New York'])
]
Run Code Online (Sandbox Code Playgroud)
我想将每个元组中的列表展平为lst. 我发现这个如何从列表列表中制作平面列表?但不知道如何使其适合我的情况。
python ×4
list ×2
apache-spark ×1
bigdata ×1
dictionary ×1
embedded ×1
javascript ×1
json ×1
node.js ×1
pyspark ×1
python-3.x ×1
scipy ×1
serial-port ×1
tuples ×1