这是我的数组的结果
df['hour'] = df.Time.str.split(":").str[0]
df['minute'] = df.Time.str.split(":").str[1]
print (df)
Time hour minute
0 10:23:00 10 23
1 11:23:00 11 23
我需要使用exp的其他值来从这个数组中获取一些值。如果我在两个单独的数组中有第四个索引的值。
Array
(
[1] => Array
(
[0] => ABC
[1] => abc
[2] => rodriguez
[3] => Barkleys, 15 NO.
[4] => A
[5] => 1234567890
[6] =>
[7] => YES
[8] => a
)
[2] => Array
(
[0] => DEF
[1] => def
[2] => DAM
[3] => Barkleys, 15 NO.
[4] => A
[5] => 1234567891
[6] =>
[7] => YES
[8] => b
)
[3] => Array
(
[0] => GHI
[1] => ghi
[2] => TEG
[3] => Street4
[4] => B
[5] => 1234567892
[6] => YES
[7] =>
[8] => c
)
[4] => Array
(
[0] => JKL
[1] => jkl
[2] => CHA
[3] => Street4
[4] => B
[5] => 1234567893
[6] => YES
[7] =>
[8] => d
)
)
现在我需要使用以上两个数组值
获取两个单独数组中第二个索引的值array (
[0] => A
[1] => A
)
array (
[0] => B
[1] => B
)
我该怎么做才能提出解决方案。
答案 0 :(得分:0)
您可以尝试这样做:
<?php
$firstArray = array();
foreach($bigArray as $key => $array) {
$value = $array[4]; //fetch the 4th indice
if(! isset($firstArray[$value])) {
$firstArray[$value] = array();
}
$firstArray[$value][$key] = $value;
}
$secondArray = array();
foreach($firstArray as $name => $array) {
foreach($array as $key => $info) {
$value = $bigArray[$key][2]; //fetch the 2nd indice
if(! isset($secondArray[$value])) {
$secondArray[$value] = array();
}
$secondArray[$value][$key] = $value;
}
}