我有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。如何解决这个问题呢?
谢谢
我使用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_tax和trip_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)