我正在尝试获取包含5列数据的数据集,并按从低到高的顺序对每一行中的数据进行排序。到目前为止,我已经想出了一种将在0-4之间循环并返回值的方法,但是由于无法弄清楚如何为所有5个行值创建列,我陷入了困境。任何帮助将不胜感激。
<?php
session_start();
require_once 'vendor/autoload.php';
$CLIENT_ID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com";
$id_token = $_POST['idtoken'];
$client = new Google_Client(['client_id' => $CLIENT_ID]);
$payload = $client->verifyIdToken($id_token);
if ($payload) {
$link = new mysqli('localhost', 'my_user', 'my_password', 'my_db');
$Test=false;
$result = $link->query("SELECT Mail FROM MyTable");
while ($row = $result->fetch_assoc()) {
if ($row['Mail']==$payload['email']) {
$Test=true;
}
}
if ($Test==true) {
//code here for success?
}
else {
//code here for failure?
}
} else {
die();
}
?>
数据:
import pandas as pd
import csv
import numpy as np
df = pd.read_csv('ValueOrder.csv')
df_2 = pd.DataFrame()
for val in [0,1,2,3,4]:
df_2 = df_2.assign(val=df.apply(lambda x: np.partition(x, val)[val], axis='columns'))
print(df_2)
预期结果:
S1 S2 S3 S4 S5
1629027 1627752 203145 1713 203458
1629027 45222 1627752 203145 1713
1629027 203458 203145 1627752 1713
1627752 203145 203458 45222 1629027
1627752 203145 1629027 1713 45222
答案 0 :(得分:0)
尝试:
pd.DataFrame(np.sort(df.values, axis=1), index=df.index, columns=df.columns)
输出:
S1 S2 S3 S4 S5
0 1713 203145 203458 1627752 1629027
1 1713 45222 203145 1627752 1629027
2 1713 203145 203458 1627752 1629027
3 45222 203145 203458 1627752 1629027
4 1713 45222 203145 1627752 1629027