//Add click event for any child div of div = grid
$(document).ready(function(){
$('.grid').on('click', 'div', function(e){
GetGridElementsPosition($(this).index()); //Pass in the index of the clicked div
//Relevant to its siblings, in other words if this is the 5th div in the div = grid
});
});
function GetGridElementsPosition(index){
//Get the css attribute grid-template-columns from the css of class grid
//split on whitespace and get the length, this will give you how many columns
const colCount = $('.grid').css('grid-template-columns').split(' ').length;
const rowPosition = Math.floor(index / colCount);
const colPosition = index % colCount;
//Return an object with properties row and column
return { row: rowPosition, column: colPosition } ;
}
Здесь лучше использовать set_index
:
s1354Ser = bus1354.set_index('Timestamp')['Speed']
Пример :
bus1354 = pd.DataFrame(
{'Timestamp':['08:38:00:009','08:38:00:013','08:38:00:019'],
'Speed':[42,42,43]})
print (bus1354)
Timestamp Speed
0 08:38:00:009 42
1 08:38:00:013 42
2 08:38:00:019 43
bus1354['Timestamp'] = pd.to_datetime(bus1354['Timestamp'].str[:7])
bus1354['Speed'] = bus1354['Speed'].astype(float)
s1354Ser = bus1354.set_index('Timestamp')['Speed']
print (s1354Ser)
Timestamp
2019-01-19 08:38:00 42.0
2019-01-19 08:38:00 42.0
2019-01-19 08:38:00 43.0
Name: Speed, dtype: float64
Отсутствующие значения в вашем Решение проблемы выравнивания данных:
#sample data
df = pd.DataFrame(
{'a':[0,2,3],
'b':[41,42,43]})
print (df)
a b
0 0 41
1 2 42
2 3 43
Если проверить индекс исходных данных:
print (df.index.tolist())
[0, 1, 2]
И значения столбца a
, используемые для нового индекса:
print (df['a'].tolist())
[0, 2, 3]
[ 1122] Затем Series
конструктор, если возможно, выровняет данные - старый индекс из исходного по новому индексу из столбца a
, если значение не существует, создаются NaN
с:
s = pd.Series(df['b'], index=df['a'])
print (s)
a
0 41.0 <-align by 0 from original index
2 43.0 <-align by 2 from original index
3 NaN <- not exist 3, so NaN
Name: b, dtype: float64
Но если преобразовать значения Speed
к numy 1d массиву по values
, тогда массив не имеет индекса, подобного Series
:
s1354Ser = pd.Series(bus1354['Speed'].values, index=bstimeRng)
s = pd.Series(df['b'].values, index=df['a'])
print (s)
a
0 41
2 42
3 43
dtype: int64