【发布时间】:2017-01-02 08:12:24
【问题描述】:
我现在拥有的:
import numpy as np
# 1) Read CSV with headers
data = np.genfromtxt("big.csv", delimiter=',', names=True)
# 2) Get absolute values for column in a new ndarray
new_ndarray = np.absolute(data["target_column_name"])
# 3) Append column in new_ndarray to data
# I'm having trouble here. Can't get hstack, concatenate, append, etc; to work
# 4) Sort by new column and obtain a new ndarray
data.sort(order="target_column_name_abs")
我想要:
- 3) 的解决方案:能够将此新的“abs”列添加到原始 ndarray 或
- 另一种能够按列的绝对值对 csv 文件进行排序的方法。
【问题讨论】:
-
它不工作的原因是形状不同。尝试 new_ndarray.shape() 并与 ata["target_column_name"].shape() 进行比较
标签: python python-3.x csv numpy