【发布时间】:2021-03-03 05:29:37
【问题描述】:
我有这个代码:-
y = digits.target
print(y[31:60])
with output [9 5 5 6 5 0 9 8 9 8 4 1 7 7 3 5 1 0 0 2 2 7 8 2 0 1 2 6 3]
y = digits.target
ans_2 = pd.Series.value_counts(y)
ans = ans_2.sort_index()
with output
0 178
1 182
2 177
3 183
4 181
5 182
6 181
7 179
8 174
9 180
现在,我想编写一个代码来创建一个新的array,其中 +1 替换每次出现的 9 并且所有其他条目(即数字 0 到 8 )应替换为 -1。此外,创建一个 Pandas Series(带有排序索引),记录每个类 Pandas Series 的计数,索引上的整数为 -1− 和 +1(按升序排序),并将相应的计数作为数据。我想通过numpy.where、numpy.unique和pandas.Series.value_counts使用这些函数来解决它。
【问题讨论】:
标签: python arrays pandas numpy