我想按系列中第二个“列”对熊猫系列的值进行排序。
这是我的代码:
ReactDOM.render(<MyComponent/>, document.getElementById(id));
这是我要排序的数据示例:
merged_clean.groupby('weeknum')['time_hour'].value_counts()
想法是对它进行排序,以便按time_hour对其进行排序。我知道我已经尝试过了
weeknum time_hour
16-22Jun 10.0 50
11.0 50
15.0 44
12.0 41
14.0 38
13.0 34
16.0 33
8.0 30
9.0 29
18.0 28
20.0 28
21.0 23
19.0 20
17.0 19
22.0 16
7.0 12
23.0 8
0.0 5
6.0 5
3.0 4
1.0 3
2.0 3
4.0 2
5.0 2
2-8Jun 11.0 66
12.0 56
9.0 55
13.0 53
10.0 52
14.0 41
但是从我看来,这将按值对行进行排序
答案 0 :(得分:2)
解释在这里https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.sort_values.html
merged_clean.groupby('weeknum')['time_hour'].value_counts().sort_values().sort_index(level=1)
答案 1 :(得分:2)
在名称或数字指定的第二级使用Series.sort_index
:
C\#
或者:
// Initial Variables
let line = '----------------------------------';
let chars = [
"/\^$.|?*+()[]{}/g", // 17 specials
"C++", // 1 char 2 specials
"Nothing Special Here" // 18 chars
];
let regexPattern = /(\\|\^|\$|\.|\||\?|\*|\+|\(|\)|\[|\]|\{|\})/g;
// let regexPattern = new RegExp(/(\\|\^|\$|\.|\||\?|\*|\+|\(|\)|\[|\]|\{|\})/, 'g');
// Main
function main() {
let explode = [];
console.log(`${line} Test Strings`);
for (let i = 0; i < chars.length; i++) {
console.log(`[${i}]: ${chars[i]}`);
if (regexPattern.test(chars[i])) {
explode[i] = chars[i].split('');
}
}
console.log(`${line} Test Strings Explodes/Splits`);
for (let i = 0; i < explode.length; i++) {
console.log(`[${i}]: ${explode[i]} \n ${line}`);
if (regexPattern.test(explode[i])) {
for (let j = 0; j < explode[i].length; j++) {
console.log(`explode[${i}][${j}] - ${explode[i][j]}`);
if (regexPattern.test(explode[i][j])) {
console.log(true);
} else {
console.log(false);
}
}
}
}
}
main();
但是如果需要在const render = () => {
ReactDOM.render(
<Provider store={createStore(my_global_todo)}>
<Rendertodo />
</Provider >
, document.getElementById('root')
);
};
中对两个级别进行排序:
merged_clean.groupby('weeknum')['time_hour'].value_counts().sort_index(level=['time_hour'])