小编ste*_*eve的帖子

使用 ctypes 将字符串作为 char 指针数组传递

我有C这个签名的功能:

int fileopen(const char *fname, int flags)

在Linux系统中,我想fname使用Python传递,ctypes所以我使用ctypes.c_char_p("file1.dat")如下:

import ctypes as ctypes

dll_name = "IO/pyaio.so"
dllabspath = os.path.dirname(os.path.abspath(__file__)) + os.path.sep + dll_name
pyaio = ctypes.CDLL(dllabspath)

fd_w = pyaio.fileopen(ctypes.c_char_p("file1.dat"), 1)
Run Code Online (Sandbox Code Playgroud)

但我收到这个错误:

Traceback (most recent call last):
  File "test.py", line 21, in <module>
    fd_w = pyaio.fileopen(ctypes.c_char_p("file1.dat"), 1) # 0 read, 1 write
TypeError: bytes or integer address expected instead of str instance
Run Code Online (Sandbox Code Playgroud)

"file1.dat"除了使用 之外,我不知道还有其他传递字符串的方法ctypes.c_char_p。如何解决这个问题呢?

谢谢

python ctypes python-3.x

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

为什么在Pandas数据帧中使用Z-score进行标准化会生成NaN列?

我使用Z-score scipy来标准化我的数据集,如下所示:

import numpy as np
import pandas as pd
from scipy import stats
from scipy.stats import zscore

df = pd.DataFrame(pd.read_csv('dataset.csv', sep=','))
df = df.dropna(how='any') # drop nan entries
df = df[(np.abs(stats.zscore(df)) < 3).all(axis=1)] # remove outliers

print(df.describe())
df = df.apply(zscore) # Normalization
print(df.describe())
Run Code Online (Sandbox Code Playgroud)

不过,我得到了一些列改为NaN,特别是mta_taxtrip_type你见下文,但他们采用的Z分数标准化前的数值.这是我的代码中的错误还是Z分数可以生成NaN

在规范化之前:

           VendorID    RatecodeID  PULocationID  DOLocationID  \
count  1.055286e+07  1.055286e+07  1.055286e+07  1.055286e+07   
mean   1.794324e+00  1.000000e+00  1.106734e+02  1.285285e+02   
std    4.041947e-01  4.353414e-04  7.541486e+01  7.729142e+01   
min    1.000000e+00  1.000000e+00  1.000000e+00  1.000000e+00 …
Run Code Online (Sandbox Code Playgroud)

python statistics python-3.x pandas

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

标签 统计

python ×2

python-3.x ×2

ctypes ×1

pandas ×1

statistics ×1