jQuery: how to go into sort mode, get out of it, apply order, and cancel sort?
Date : March 29 2020, 07:55 AM
This might help you If you have a button that you want to use to "Start Sorting" the sortable, I would recommend this approach, assuming you have a DIV with an ID of "MyList"... On document load or Init, create the sortable and deactivate it... $(init);
function init() {
$("#MyLIst").sortable();
$("#MyLIst").sortable("disable");
}
$("#MyLIst").sortable("enable");
$("#MyLIst").sortable("disable");
|
How to apply a secondary sort for ruby array with reversed sort direction?
Date : March 29 2020, 07:55 AM
I hope this helps you . I have a ruby array in the format of [["Anna",70],["Billy",90],["Billy",100]]... , You can easily do it with sort_by{ |o| [o.name, -o.score]}
|
Pandas: How to flag a column with groupy & apply()
Date : March 29 2020, 07:55 AM
To fix the issue you can do Right now, my code will return the rows that meet the condition in my function. How can I instead return all original rows and flag a new column ('GreaterDate) if the condition is true? , Here is one way: def date_compare(df):
df['dftest'] = df['Date2'] == df['Date1'].shift(-1)
return df
dftest = pd.concat([df[df.KEY == k].pipe(date_compare) \
for k in set(df.KEY)], ignore_index=True)
# Date1 Date2 KEY dftest
# 0 20120506 20120507 100000009 True
# 1 20120507 20120615 100000009 False
# 2 20120608 20120629 100000009 False
# 3 20120620 20120206 100000009 False
# 4 20120206 20120305 100000034 False
# 5 20120306 20120506 100000034 True
# 6 20120506 20120506 100000034 False
# 7 20120506 20120528 100000003 False
|
ValueError: cannot reindex from a duplicate axis using groupy and apply pct_change in Pandas
Date : March 29 2020, 07:55 AM
This might help you I get this same error if i have duplicates in my index. You'll need to reset_index(): In [726]: df.append(df)
Out[726]:
customer brand product quantity price new_quantity
0 C1 B1 P1 100 5 500
1 C1 B1 P2 10 20 200
2 C1 B2 P3 50 7 350
3 C2 B1 P1 75 5 375
4 C2 B2 P3 5 7 35
0 C1 B1 P1 100 5 500
1 C1 B1 P2 10 20 200
2 C1 B2 P3 50 7 350
3 C2 B1 P1 75 5 375
4 C2 B2 P3 5 7 35
df.groupby('customer')['quantity'].apply(lambda x: x.pct_change())
# ValueError: cannot reindex from a duplicate axis
In [730]: df.append(df).reset_index().groupby('customer')['quantity'].apply(lambda x: x.pct_change())
Out[730]:
0 NaN
1 -0.900000
2 4.000000
3 NaN
4 -0.933333
5 1.000000
6 -0.900000
7 4.000000
8 14.000000
9 -0.933333
Name: quantity, dtype: float64
|
Ascending sort order Index versus descending sort order index when performing OrderBy
Date : March 29 2020, 07:55 AM
|