我有两个不同的数组,一个是字符串,另一个是整数.我想将它们连接到一个数组中,其中每列都具有原始数据类型.我目前的解决方案(见下文)将整个数组转换为dtype = string,这看起来非常低效.
combined_array = np.concatenate((A, B), axis = 1)
是否有可能多发dtypes的combined_array时候A.dtype = string和B.dtype = int?
我有两个系列,其格式与此相同:
0 False
1 False
2 False
3 True
4 True
Name: foo, dtype: bool
0 True
1 False
2 False
3 True
4 True
Name: bar, dtype: bool
Run Code Online (Sandbox Code Playgroud)
我想创建一个新系列,并从中得到布尔比较.像这样的东西:
result = foo and bar
>>> print result
0 False
1 False
2 False
3 True
4 True
Name: result, dtype: bool
Run Code Online (Sandbox Code Playgroud)
使用显而易见的result = foo and bar结果会导致以下错误:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Run Code Online (Sandbox Code Playgroud)
我查看了这些功能,但似乎都没有按照我的意愿行事.
如何对系列进行元素到元素的布尔比较,从而产生新系列?
如果这是一个愚蠢的问题,请随意骚扰我,因为我没有找到正确的答案.我正在尝试读取包含每行数据的CSV格式文件,每行以逗号结束.像这样:
-1,
-1,
1,
1,
Run Code Online (Sandbox Code Playgroud)
当我尝试使用Python的CSV函数时,我使用以下代码:
with open(waveform, 'rb') as f:
reader = csv.reader(f)
for row in reader:
print row
Run Code Online (Sandbox Code Playgroud)
其中输出如下:
['-1', '']
['-1', '']
['1', '']
['1', '']
Run Code Online (Sandbox Code Playgroud)
我希望它忽略每行上的空字符.你有什么建议吗?