Pandas sort not sorting data properly - python-3.x

I am trying to sort the results of sklearn.ensemble.RandomForestRegressor's feature_importances_
I have the following function:
def get_feature_importances(cols, importances):
feats = {}
for feature, importance in zip(cols, importances):
feats[feature] = importance
importances = pd.DataFrame.from_dict(feats, orient='index').rename(columns={0: 'Gini-importance'})
importances.sort_values(by='Gini-importance')
return importances
I use it like so:
importances = get_feature_importances(X_test.columns, rf.feature_importances_)
print()
print(importances)
And I get the following results:
| PART | 0.035034 |
| MONTH1 | 0.02507 |
| YEAR1 | 0.020075 |
| MONTH2 | 0.02321 |
| YEAR2 | 0.017861 |
| MONTH3 | 0.042606 |
| YEAR3 | 0.028508 |
| DAYS | 0.047603 |
| MEDIANDIFF | 0.037696 |
| F2 | 0.008783 |
| F1 | 0.015764 |
| F6 | 0.017933 |
| F4 | 0.017511 |
| F5 | 0.017799 |
| SS22 | 0.010521 |
| SS21 | 0.003896 |
| SS19 | 0.003894 |
| SS23 | 0.005249 |
| SS20 | 0.005127 |
| RR | 0.021626 |
| HI_HOURS | 0.067584 |
| OI_HOURS | 0.054369 |
| MI_HOURS | 0.062121 |
| PERFORMANCE_FACTOR | 0.033572 |
| PERFORMANCE_INDEX | 0.073884 |
| NUMPA | 0.022445 |
| BUMPA | 0.024192 |
| ELOH | 0.04386 |
| FFX1 | 0.128367 |
| FFX2 | 0.083839 |
I thought the line importances.sort_values(by='Gini-importance') would sort them. But it is not. Why is this not performing correctly?

importances.sort_values(by='Gini-importance') returns the sorted dataframe, which is overlooked by your function.
You want return importances.sort_values(by='Gini-importance').
Or you could make sort_values inplace:
importances.sort_values(by='Gini-importance', inplace=True)
return importances

Related

Remove groups from pandas where {condition}

I have dataframe like this:
+---+--------------------------------------+-----------+
| | envelopeid | message |
+---+--------------------------------------+-----------+
| 1 | d55edb65-dc77-41d0-bb53-43cf01376a04 | CMN.00002 |
| 2 | d55edb65-dc77-41d0-bb53-43cf01376a04 | CMN.00004 |
| 3 | d55edb65-dc77-41d0-bb53-43cf01376a04 | CMN.11001 |
| 4 | 5cb72b9c-adb8-4e1c-9296-db2080cb3b6d | CMN.00002 |
| 5 | 5cb72b9c-adb8-4e1c-9296-db2080cb3b6d | CMN.00001 |
| 6 | f4260b99-6579-4607-bfae-f601cc13ff0c | CMN.00202 |
| 7 | 8f673ae3-0293-4aca-ad6b-572f138515e6 | CMN.00002 |
| 8 | fee98470-aa8f-4ec5-8bcd-1683f85727c2 | TKP.00001 |
| 9 | 88926399-3697-4e15-8d25-6cb37a1d250e | CMN.00002 |
| 10| 88926399-3697-4e15-8d25-6cb37a1d250e | CMN.00004 |
+---+--------------------------------------+-----------+
I've grouped it with grouped = df.groupby('envelopeid')
And I need to remove all groups from the dataframe and stay only that groups that have messages (CMN.00002) or (CMN.00002 and CMN.00004) only.
Desired dataframe:
+---+--------------------------------------+-----------+
| | envelopeid | message |
+---+--------------------------------------+-----------+
| 7 | 8f673ae3-0293-4aca-ad6b-572f138515e6 | CMN.00002 |
| 9 | 88926399-3697-4e15-8d25-6cb37a1d250e | CMN.00002 |
| 10| 88926399-3697-4e15-8d25-6cb37a1d250e | CMN.00004 |
+---+--------------------------------------+-----------+
tried
(grouped.message.transform(lambda x: x.eq('CMN.00001').any() or (x.eq('CMN.00002').any() and x.ne('CMN.00002' or 'CMN.00004').any()) or x.ne('CMN.00002').all()))
but it is not working properly
Try:
grouped = df.loc[df['message'].isin(['CMN.00002', 'CMN.00002', 'CMN.00004'])].groupby('envelopeid')
Try this: df[df.message== 'CMN.00002']
outdf = df.groupby('envelopeid').filter(lambda x: tuple(x.message)== ('CMN.00002',) or tuple(x.message)== ('CMN.00002','CMN.00004'))
So i figured it up.
resulting dataframe will got only groups that have only CMN.00002 message or CMN.00002 and CMN.00004. This is what I need.
I used filter instead of transform.

AVPlayer crash on fullscreen

On iOS 13.3.1 the AVPlayer fullscreen is crashing. Once I rotate the screen the Xcode console shows an error Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
I have added a symbolic breakpoint, and debugger catch the following error
UIWindow:0x108b99360
| UITransitionView:0x108c53a10
| | UIView:0x11be462b0
| | | UIView:0x11beab9d0
| | | UIView:0x11a7c9890
| | | UIView:0x11bebacc0
| | | UIView:0x11be10d00
| | UIDropShadowView:0x113c14b00
| | | UILayoutContainerView:0x108bf0790
| | | | UITransitionView:0x108bc1410
| | | | | UIViewControllerWrapperView:0x108ba1590
| | | | | | •UILayoutContainerView:0x108ba25c0
| | | | | | | +UINavigationTransitionView:0x108bc04b0
| | | | | | | | +UIViewControllerWrapperView:0x11ae32650
| | | | | | | | | •UIView:0x11a7c90f0
| | | | | | | | | | *<UILayoutGuide: 0x280700b60 - "UIViewSafeAreaLayoutGuide", layoutFrame = {{0, 20}, {667, 425}}, owningView = <UIView: 0x11a7c90f0; frame = (0 0; 667 375); autoresize = W+H; animations = { position=<CABasicAnimation: 0x283e654e0>; bounds.origin=<CABasicAnimation: 0x283e65420>; bounds.size=<CABasicAnimation: 0x283e65460>; position-2=<CABasicAnimation: 0x283e60a20>; bounds.origin-2=<CABasicAnimation: 0x283e60980>; bounds.size-2=<CABasicAnimation: 0x283e60920>; }; layer = <CALayer: 0x283ebb900>>>- AMBIGUOUS LAYOUT for UILayoutGuide:0x280700b60'UIViewSafeAreaLayoutGuide'.Height{id: 8167}
| | | | | | | | | | *UIView:0x11a7c8e10
| | | | | | | | | | | •UIView:0x11ae5b960
| | | | | | | | | | | | *<UILayoutGuide: 0x28071fc60 - "UIViewSafeAreaLayoutGuide", layoutFrame = {{0, 0}, {375, 375}}, owningView = <UIView: 0x11ae5b960; frame = (0 0; 375 375); autoresize = W+H; gestureRecognizers = <NSArray: 0x2830ff750>; layer = <CALayer: 0x283f1b6a0>>>
| | | | | | | | | | | | *UIView:0x11ae598b0
| | | | | | | | | | | | *UIImageView:0x108ba76e0
| | | | | | | | | | | | *UIButton:0x11aea33b0
| | | | | | | | | | | | | UIImageView:0x108cf2320
| | | | | | | | | | | | *UILabel:0x11aea3660'Tap to reload'
| | | | | | | | | | | | *NTV.GradientView:0x11ae77740
| | | | | | | | | | | | | *UIView:0x108ba8140
| | | | | | | | | | | | | | *UILabel:0x108b93db0'Now Playing- Swasthya Sar...'
| | | | | | | | | | | | | | *UILabel:0x108ba64a0'2020-02-14 09:30 - 10:00'
| | | | | | | | | | | | | *UILabel:0x114c062e0'11:59:23'
| | | | | | | | | | | | | *UISlider:0x108ba8870 alignmentRect = (16 300.5; 343 18.5) for frame = (14 300.5; 347 19.5);
| | | | | | | | | | | | | | *UIProgressView:0x108c3b7c0
| | | | | | | | | | | | | | | UIImageView:0x108c142a0
| | | | | | | | | | | | | | | UIImageView:0x108c06090
| | | | | | | | | | | | | | UIView:0x11bea2880
| | | | | | | | | | | | | | | UIImageView:0x11bea2b60
| | | | | | | | | | | | | | UIView:0x11bea29f0
| | | | | | | | | | | | | | | UIImageView:0x11bea4b20
| | | | | | | | | | | | | | UIImageView:0x11bea4cf0
| | | | | | | | | | | | | *UILabel:0x11ae01e00'00:00'
| | | | | | | | | | | | | *UILabel:0x108ba3e70'🔴LIVE'
| | | | | | | | | | | | | *UIView:0x113c7d1e0
| | | | | | | | | | | | | | *UIStackView:0x113c61b80
| | | | | | | | | | | | | | | *UIButton:0x108ba40e0
| | | | | | | | | | | | | | | | UIImageView:0x108cf24f0
| | | | | | | | | | | | | | | *UIActivityIndicatorView:0x114c16df0
| | | | | | | | | | | | | | | | UIImageView:0x114c0c0d0
| | | | | | | | | | | | | | | *UIButton:0x113c5f6d0
| | | | | | | | | | | | | | | | UIImageView:0x108cf26c0
| | | | | | | | | | | | | | | *UIButton:0x113c4e840
| | | | | | | | | | | | | | | | UIImageView:0x108c24720
| | | | | | | | | | | | | | | *UIButton:0x11ae31150
| | | | | | | | | | | | | | | | UIImageView:0x108c248f0
| | | | | | | | | | | | | | *UIButton:0x113c37f90'Auto'
| | | | | | | | | | | | | | | UIButtonLabel:0x11bea2170'Auto'
| | | | | | | | | | | | | | *UIStackView:0x11ae30d80
| | | | | | | | | | | | | | | *<_UIOLAGapGuide: 0x280208a00 - "UISV-distributing", layoutFrame = {{30, 0}, {12, 0}}, owningView = <UIStackView: 0x11ae30d80; frame = (265 10; 94 20); opaque = NO; autoresize = RM+BM; layer = <CATransformLayer: 0x283f1ad80>>>- AMBIGUOUS LAYOUT for _UIOLAGapGuide:0x280208a00'UISV-distributing'.minY{id: 9088}, _UIOLAGapGuide:0x280208a00'UISV-distributing'.Height{id: 9089}
| | | | | | | | | | | | | | | *<_UIOLAGapGuide: 0x28021c600 - "UISV-distributing", layoutFrame = {{62, 0}, {12, 0}}, owningView = <UIStackView: 0x11ae30d80; frame = (265 10; 94 20); opaque = NO; autoresize = RM+BM; layer = <CATransformLayer: 0x283f1ad80>>>- AMBIGUOUS LAYOUT for _UIOLAGapGuide:0x28021c600'UISV-distributing'.minY{id: 9090}, _UIOLAGapGuide:0x28021c600'UISV-distributing'.Height{id: 9091}
| | | | | | | | | | | | | | | *UIButton:0x11ae967d0
| | | | | | | | | | | | | | | | UIImageView:0x108c54740
| | | | | | | | | | | | | | | *UIButton:0x11aea1a50
| | | | | | | | | | | | | | | | UIImageView:0x11a757f70
| | | | | | | | | | | | | | | *AVRoutePickerView:0x108c4f1d0
| | | | | | | | | | | | | | | | *UIButton:0x108c227f0
| | | | | | | | | | | | | | | | | UIButtonLabel:0x11be29d30
| | | | | | | | | | *UIView:0x11a7c9260- AMBIGUOUS LAYOUT for UIView:0x11a7c9260.Height{id: 8163}
| | | | | | | | | | | *XLPagerTabStrip.ButtonBarView:0x109a18c00
| | | | | | | | | | | | •XLPagerTabStrip.ButtonBarViewCell:0x11be6b470
| | | | | | | | | | | | | *UIView:0x11be6b870
| | | | | | | | | | | | | | *<UILayoutGuide: 0x280701420 - "UIViewSafeAreaLayoutGuide", layoutFrame = {{0, 0}, {162.5, 40}}, owningView = <UIView: 0x11be6b870; frame = (0 0; 162.5 40); gestureRecognizers = <NSArray: 0x28312e910>; layer = <CALayer: 0x283e8db00>>>
| | | | | | | | | | | | | | *UILabel:0x11be6b9e0'LIVE CHANNEL'
| | | | | | | | | | | | | | *UIImageView:0x11be6be40
| | | | | | | | | | | | •XLPagerTabStrip.ButtonBarViewCell:0x11be6d2a0
| | | | | | | | | | | | | *UIView:0x11be6d4a0
| | | | | | | | | | | | | | *<UILayoutGuide: 0x280701500 - "UIViewSafeAreaLayoutGuide", layoutFrame = {{0, 0}, {162.5, 40}}, owningView = <UIView: 0x11be6d4a0; frame = (0 0; 162.5 40); gestureRecognizers = <NSArray: 0x28312c5a0>; layer = <CALayer: 0x283e8d500>>>
| | | | | | | | | | | | | | *UILabel:0x11be6d610'LIVE EVENTS'
| | | | | | | | | | | | | | *UIImageView:0x11be6d880
| | | | | | | | | | | | UIView:0x108c303b0
| | | | | | | | | | | | _UIScrollViewScrollIndicator:0x108bf1d10
| | | | | | | | | | | | | UIView:0x11ae577e0
| | | | | | | | | | | *UIView:0x11a7c8f80
| | | | | | | | | | | *UIScrollView:0x109a15000- AMBIGUOUS LAYOUT for UIScrollView:0x109a15000.Height{id: 8164}
| | | | | | | | | | | | •UIView:0x11be60eb0
| | | | | | | | | | | | | *<UILayoutGuide: 0x280701260 - "UIViewSafeAreaLayoutGuide", layoutFrame = {{0, 0}, {375, 173}}, owningView = <UIView: 0x11be60eb0; frame = (0 0; 375 173); autoresize = W+H; layer = <CALayer: 0x283eb6f20>>>
| | | | | | | | | | | | | *UICollectionView:0x109a48400
| | | | | | | | | | | | | | •NTV.LiveChannelCollectionViewCell:0x11ae5b750
| | | | | | | | | | | | | | | *UIView:0x11ae5bb60
| | | | | | | | | | | | | | | | *UIView:0x11ae5bcd0
| | | | | | | | | | | | | | | | | *UIImageView:0x11ae5be40
| | | | | | | | | | | | | | | | *UILabel:0x11ae5c190'NTV'
| | | | | | | | | | | | | | •NTV.LiveChannelCollectionViewCell:0x11ae5d820
| | | | | | | | | | | | | | | *UIView:0x11ae5da30
| | | | | | | | | | | | | | | | *UIView:0x11ae5dba0
| | | | | | | | | | | | | | | | | *UIImageView:0x11ae5dd10
| | | | | | | | | | | | | | | | *UILabel:0x11ae5e060'NTV Plus'
| | | | | | | | | | | | | | •NTV.LiveChannelCollectionViewCell:0x11ae5f3d0
| | | | | | | | | | | | | | | *UIView:0x11ae5f5e0
| | | | | | | | | | | | | | | | *UIView:0x11ae5f750
| | | | | | | | | | | | | | | | | *UIImageView:0x11ae5f8c0
| | | | | | | | | | | | | | | | *UILabel:0x11ae5fc10'NTV News'
| | | | | | | | | | | | | | •NTV.LiveChannelCollectionViewCell:0x11be64720
| | | | | | | | | | | | | | | *UIView:0x11be64930
| | | | | | | | | | | | | | | | *UIView:0x11be64aa0
| | | | | | | | | | | | | | | | | *UIImageView:0x11be64c10
| | | | | | | | | | | | | | | | *UILabel:0x11be64f60'NTV Kohalpur'
| | | | | | | | | | | | | | •NTV.LiveChannelCollectionViewCell:0x11be66400
| | | | | | | | | | | | | | | *UIView:0x11be66610
| | | | | | | | | | | | | | | | *UIView:0x11be66780
| | | | | | | | | | | | | | | | | *UIImageView:0x11be668f0
| | | | | | | | | | | | | | | | *UILabel:0x11be66c40'NTV Itahari'
| | | | | | | | | | | | | *UIView:0x11be61020
| | | | | | | | | | | | | | *UIView:0x11be61190
| | | | | | | | | | | | | | | *UIImageView:0x11be603e0
| | | | | | | | | | | | | | | *UILabel:0x11be605b0'NTV'
| | | | | | | | | | | | | | | *UIButton:0x11be60a10' MORE SCHEDULE '
| | | | | | | | | | | | | | | | UIButtonLabel:0x11ae5a230' MORE SCHEDULE '
| | | | | | | | | | | | | | | *UIView:0x11be61300
| | | | | | | | | | | | | | *UIView:0x11be61770
| | | | | | | | | | | | | | | *UIImageView:0x11a7c9a40
| | | | | | | | | | | | | | | *UIImageView:0x11a73d9c0
| | | | | | | | | | | | | | | *UICollectionView:0x1098e3400
| | | | | | | | | | | | | | | | •NTV.EPGCollectionViewCell:0x11be2aad0
| | | | | | | | | | | | | | | | | *UIView:0x11be2ace0
| | | | | | | | | | | | | | | | | | *UIImageView:0x11be2ae50
| | | | | | | | | | | | | | | | | | *UILabel:0x11bebbbf0'08:00 - 08:25'
| | | | | | | | | | | | | | | | | | *UILabel:0x11bebbe60'The News'
| | | | | | | | | | | | | | | | | | *UIView:0x11bebc0d0
| | | | | | | | | | | | | | | | | | *UILabel:0x11bebc240' On Air '
| | | | | | | | | | | | | | | | •NTV.EPGCollectionViewCell:0x11beb0cf0
| | | | | | | | | | | | | | | | | *UIView:0x11beae950
| | | | | | | | | | | | | | | | | | *UIImageView:0x11beb0220
| | | | | | | | | | | | | | | | | | *UILabel:0x11beb0f00'09:00 - 09:30'
| | | | | | | | | | | | | | | | | | *UILabel:0x11beb1170'Sirjanaka Sarathi'
| | | | | | | | | | | | | | | | | | *UIView:0x11beb13e0
| | | | | | | | | | | | | | | | | | *UILabel:0x11beb1550' On Air '
| | | | | | | | | | | | | | | | •NTV.EPGCollectionViewCell:0x11beb3850
| | | | | | | | | | | | | | | | | *UIView:0x11bebe860
| | | | | | | | | | | | | | | | | | *UIImageView:0x11bebeec0
| | | | | | | | | | | | | | | | | | *UILabel:0x11bebf090'Swasthya Sarokar'
| | | | | | | | | | | | | | | | | | *UILabel:0x11bebf4c0
| | | | | | | | | | | | | | | | | | *UIView:0x11bebe9d0
| | | | | | | | | | | | | | | | | | *UILabel:0x11bebf730' On Air '
| | | | | | | | | | | | | | | | •NTV.EPGCollectionViewCell:0x11aeaf4d0
| | | | | | | | | | | | | | | | | *UIView:0x11aeaf6e0
| | | | | | | | | | | | | | | | | | *UIImageView:0x11aeaf850
| | | | | | | | | | | | | | | | | | *UILabel:0x11aeafa20'10:00 - 10:15'
| | | | | | | | | | | | | | | | | | *UILabel:0x11aeafc90'Hamro Kathmandu'
| | | | | | | | | | | | | | | | | | *UIView:0x11aeaff00
| | | | | | | | | | | | | | | | | | *UILabel:0x11aeb0070' On Air '
| | | | | | | | | | | | | | | | •NTV.EPGCollectionViewCell:0x11aebe350
| | | | | | | | | | | | | | | | | *UIView:0x11aebe560
| | | | | | | | | | | | | | | | | | *UIImageView:0x11aebd270
| | | | | | | | | | | | | | | | | | *UILabel:0x11aebd440'09:00 - 09:30'
| | | | | | | | | | | | | | | | | | *UILabel:0x11aebebc0'Sirjanaka Sarathi'
| | | | | | | | | | | | | | | | | | *UIView:0x11aebe840
| | | | | | | | | | | | | | | | | | *UILabel:0x11aebee30' On Air '
| | | | | | | | | | | | | | | | •NTV.EPGCollectionViewCell:0x11aeb6230
| | | | | | | | | | | | | | | | | *UIView:0x113c2beb0
| | | | | | | | | | | | | | | | | | *UIImageView:0x11aea7020
| | | | | | | | | | | | | | | | | | *UILabel:0x108c40a30'Swasthya Sarokar'
| | | | | | | | | | | | | | | | | | *UILabel:0x11beb9460
| | | | | | | | | | | | | | | | | | *UIView:0x11bea74d0
| | | | | | | | | | | | | | | | | | *UILabel:0x11beab180' On Air '
| | | | | | | | | | | | | | | | •NTV.EPGCollectionViewCell:0x11aeaba80
| | | | | | | | | | | | | | | | | *UIView:0x11aeabe90
| | | | | | | | | | | | | | | | | | *UIImageView:0x11aeac000
| | | | | | | | | | | | | | | | | | *UILabel:0x11aeac1d0'10:00 - 10:15'
| | | | | | | | | | | | | | | | | | *UILabel:0x11aeac630'Hamro Kathmandu'
| | | | | | | | | | | | | | | | | | *UIView:0x11aeaca90
| | | | | | | | | | | | | | | | | | *UILabel:0x11aeacc00' On Air '
| | | | | | | •UINavigationBar:0x108c24220
| | | | | | | | _UIBarBackground:0x108c37e40
| | | | | | | | | UIImageView:0x11ae59160
| | | | | | | | •_UINavigationBarContentView:0x108c4c340
| | | | | | | | | *<UILayoutGuide: 0x280714c40 - "BackButtonGuide(0x108c50bc0)", layoutFrame = {{0, 0}, {16, 32}}, owningView = <_UINavigationBarContentView: 0x108c4c340; frame = (0 0; 375 44); layer = <CALayer: 0x283e4b0a0>> layout=0x108c50bc0>
| | | | | | | | | *<UILayoutGuide: 0x280714d20 - "LeadingBarGuide(0x108c50bc0)", layoutFrame = {{16, 0}, {70, 32}}, owningView = <_UINavigationBarContentView: 0x108c4c340; frame = (0 0; 375 44); layer = <CALayer: 0x283e4b0a0>> layout=0x108c50bc0>
| | | | | | | | | *<UILayoutGuide: 0x280714e00 - "TitleView(0x108c50bc0)", layoutFrame = {{92, 0}, {231, 32}}, owningView = <_UINavigationBarContentView: 0x108c4c340; frame = (0 0; 375 44); layer = <CALayer: 0x283e4b0a0>> layout=0x108c50bc0>
| | | | | | | | | *<UILayoutGuide: 0x280716300 - "TrailingBarGuide(0x108c50bc0)", layoutFrame = {{323, 0}, {44, 32}}, owningView = <_UINavigationBarContentView: 0x108c4c340; frame = (0 0; 375 44); layer = <CALayer: 0x283e4b0a0>> layout=0x108c50bc0>
| | | | | | | | | *<UILayoutGuide: 0x280716220 - "UIViewLayoutMarginsGuide", layoutFrame = {{16, 0}, {343, 44}}, owningView = <_UINavigationBarContentView: 0x108c4c340; frame = (0 0; 375 44); layer = <CALayer: 0x283e4b0a0>> layout=0x108c50bc0>
| | | | | | | | | *_UIButtonBarStackView:0x114cdfb30
| | | | | | | | | | *<UILayoutGuide: 0x28071f1e0 - "UIViewLayoutMarginsGuide", layoutFrame = {{0, 0}, {70, 32}}, owningView = <_UIButtonBarStackView: 0x114cdfb30; frame = (16 0; 70 44); layer = <CALayer: 0x283e81140>> buttonBar=0x28071ef40>
| | | | | | | | | | *<_UILayoutSpacer: 0x280155680 - "UISV-alignment-spanner", layoutFrame = {{0, 0}, {0, 32}}, owningView = <_UIButtonBarStackView: 0x114cdfb30; frame = (16 0; 70 44); layer = <CALayer: 0x283e81140>> buttonBar=0x28071ef40>- AMBIGUOUS LAYOUT for _UILayoutSpacer:0x280155680'UISV-alignment-spanner'.minX{id: 9224}, _UILayoutSpacer:0x280155680'UISV-alignment-spanner'.Width{id: 9225}
| | | | | | | | | | *_UITAMICAdaptorView:0x114cdf6b0
| | | | | | | | | | | UIButton:0x108bcc8d0
| | | | | | | | | | | | UIImageView:0x11ae57f00
| | | | | | | | | | *UIView:0x11aea4d00
| | | | | | | | | | *_UIButtonBarButton:0x11aea5ae0
| | | | | | | | | | | *<UILayoutGuide: 0x2807031e0 - "UIViewLayoutMarginsGuide", layoutFrame = {{0, 11}, {37, 10}}, owningView = <_UIButtonBarButton: 0x11aea5ae0; frame = (33 0; 37 44); tintColor = UIExtendedGrayColorSpace 1 1; layer = <CALayer: 0x283f1b620>>>
| | | | | | | | | | | *_UIModernBarButton:0x11aea5ec0'NTV'
| | | | | | | | | | | | *UIButtonLabel:0x11bea7910'NTV'
| | | | | | | | | *_UIButtonBarStackView:0x108ba78e0
| | | | | | | | | | *<UILayoutGuide: 0x28071eca0 - "UIViewLayoutMarginsGuide", layoutFrame = {{0, 0}, {44, 32}}, owningView = <_UIButtonBarStackView: 0x108ba78e0; frame = (323 0; 44 44); layer = <CALayer: 0x283e841c0>> buttonBar=0x28071ebc0>
| | | | | | | | | | *_UIButtonBarButton:0x114c16590
| | | | | | | | | | | UILabel:0x108c4ff70'0'
| | | | | | | | | | | *_UIModernBarButton:0x114c16770
| | | | | | | | | | | | UIImageView:0x114c14c00
| | | | UITabBar:0x108bf0990
| | | | | _UIBarBackground:0x108bf34f0
| | | | | | _UIBarBackgroundShadowView:0x108bf5d80
| | | | | | | _UIBarBackgroundShadowContentImageView:0x108bfb190
| | | | | | UIImageView:0x113c0bc10
| | | | | UITabBarButton:0x113c10f70
| | | | | | UITabBarSwappableImageView:0x113c11530
| | | | | | UITabBarButtonLabel:0x113c11290'Home'
| | | | | UITabBarButton:0x113c11ed0
| | | | | | UITabBarSwappableImageView:0x113c12490
| | | | | | UITabBarButtonLabel:0x113c121f0'Live'
| | | | | UITabBarButton:0x113c12e30
| | | | | | UITabBarSwappableImageView:0x113c0dea0
| | | | | | UITabBarButtonLabel:0x113c13150'TV Shows'
| | | | | UITabBarButton:0x113c13ba0
| | | | | | UITabBarSwappableImageView:0x113c14160
| | | | | | UITabBarButtonLabel:0x113c13ec0'News'
| | | | | UITabBarButton:0x108c51190
| | | | | | UITabBarSwappableImageView:0x108c51de0
| | | | | | UITabBarButtonLabel:0x108c51b40'More'
| UIView:0x108bf0bb0
The issue is on iOS 13.3.1 devices and it is working for 12.4.5 devices. I have tried to change the constrains of AMBIGUOUS view but could not resolve the issue. Any help would be appreciated. Thank you.
For me, this happened because of an infinite loop under layoutSubviews. Once I fix that it was solved. Thought the crash appears only on iOS 13, the previous version of iOS has no issue with it.

Calculating frequecy (Min/Max/Average) of order placement in Excel

I need to analyze Weekly order frequencies over last 1 year period to find out what is the min/max/average frequencies of orders for each product.
whether it is new or old,system should calculate the first occurrence of the order in the year as the starting week of the order. Min order frequency is difference between successive ordering weeks. If the first order is in wk 3 and the second order is in wk6, implies the order frequency is 3 weeks (=>6-3). Orders can be at any week in the past 52 weeks. Average order frequency = (52 - First order week) / no of weeks that have orders.
Attaching the excel for better understanding the issue.
Original image
+---------+-----+-----+-----+-----+-----+-----+-----+-----+-----+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+----------------+-------------------------+-----+-----------------------------------+--+
| Product | wk1 | wk2 | wk3 | wk4 | wk5 | wk6 | wk7 | wk8 | wk9 | wk10 | wk11 | wk12 | wk13 | wk14 | wk15 | wk16 | wk17 | wk18 | wk19 | wk20 | wk21 | wk22 | wk23 | wk24 | wk25 | wk26 | wk27 | wk28 | wk29 | wk30 | wk31 | wk32 | wk33 | wk34 | wk35 | wk36 | wk37 | wk38 | wk39 | wk40 | wk41 | wk42 | wk43 | wk44 | wk45 | wk46 | wk47 | wk48 | wk49 | wk50 | wk51 | wk52 | Order start wk | Order frequency (Weeks) | | | |
+---------+-----+-----+-----+-----+-----+-----+-----+-----+-----+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+----------------+-------------------------+-----+-----------------------------------+--+
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Min | Max | Average | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (End wk - Start week)/No of times | |
| SKU 1 | | | | | | | | | y | | y | | y | | y | | y | | y | | y | | y | y | | | y | | y | | y | | y | | | | | | y | | y | | y | | y | | y | | y | | y | | 9 | 1 | 6 | 2.15 | |
| SKU 2 | | | | | | | y | | | | | | y | | | | | | y | | | | | | y | | | | | | y | | | | | | y | | | | | | y | | | | | | y | | | | 1 | 0 | 0 | 7.29 | |
| SKU 3 | | | | | | | | | | | | | | | y | | | | | | | | | | | | | | | | y | | | | | | | | y | | | | | | | | y | | | | | | 15 | 8 | 15 | 9.25 | |
+---------+-----+-----+-----+-----+-----+-----+-----+-----+-----+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+----------------+-------------------------+-----+-----------------------------------+--+
So as mentioned #Barry Houdini solves the problem of finding the longest sequence of zeroes separated by ones elegantly here
You only have to change it slightly to check for repeated blank cells separated by 'y'. The only thing is that you don't want to include cells before the first 'y', and (although this isn't clear) may not want to include blank cells after the last 'y'.
The formula for MIN becomes
=MIN(IF((ROW(A$1:INDEX(A:A,COUNTA(B4:BA4)+1))>1)*(ROW(A$1:INDEX(A:A,COUNTA(B4:BA4)+1))<COUNTA(B4:BA4)+1),FREQUENCY(IF(B4:BA4="",COLUMN(B4:BA4)),IF(B4:BA4="y",COLUMN(B4:BA4)))))+1
and the formula for MAX becomes (the same)
=MAX(IF((ROW(A$1:INDEX(A:A,COUNTA(B4:BA4)+1))>1)*(ROW(A$1:INDEX(A:A,COUNTA(B4:BA4)+1))<COUNTA(B4:BA4)+1),FREQUENCY(IF(B4:BA4="",COLUMN(B4:BA4)),IF(B4:BA4="y",COLUMN(B4:BA4)))))+1
where you need to add 1 to make the results agree with the question because #Barry's formula counts numbers of blanks but OP wants interval between two successive y's. An array of ny+1 elements is generated where ny is the number of y's. This is because the FREQUENCY function returns an array with n+1 elements where n is the number of cut points (bins_array in documentation and because the column numbers of cells containing y are used as cut points so there are ny of them.
These are both array formulas and need to be entered with CtrlShiftEnter
The formula for the average is just
=(COLUMNS(B4:BA4)-MATCH("y",B4:BA4,0))/COUNTA(B4:BA4)

Blending Model: Oil Production

Oil Blending
An oil company produces three brands of oil: Regular, Multigrade, and
Supreme. Each brand of oil is composed of one or more of four crude stocks, each having a different lubrication index. The relevant data concerning the crude stocks are as follows.
+-------------+-------------------+------------------+--------------------------+
| Crude Stock | Lubrication Index | Cost (€/barrell) | Supply per day (barrels) |
+-------------+-------------------+------------------+--------------------------+
| 1 | 20 | 7,10 | 1000 |
+-------------+-------------------+------------------+--------------------------+
| 2 | 40 | 8,50 | 1100 |
+-------------+-------------------+------------------+--------------------------+
| 3 | 30 | 7,70 | 1200 |
+-------------+-------------------+------------------+--------------------------+
| 4 | 55 | 9,00 | 1100 |
+-------------+-------------------+------------------+--------------------------+
Each brand of oil must meet a minimum standard for a lubrication index, and each brand
thus sells at a different price. The relevant data concerning the three brands of oil are as
follows.
+------------+---------------------------+---------------+--------------+
| Brand | Minimum Lubrication index | Selling price | Daily demand |
+------------+---------------------------+---------------+--------------+
| Regular | 25 | 8,50 | 2000 |
+------------+---------------------------+---------------+--------------+
| Multigrade | 35 | 9,00 | 1500 |
+------------+---------------------------+---------------+--------------+
| Supreme | 50 | 10,00 | 750 |
+------------+---------------------------+---------------+--------------+
Determine an optimal output plan for a single day, assuming that production can be either
sold or else stored at negligible cost.
The daily demand figures are subject to alternative interpretations. Investigate the
following:
(a) The daily demands represent potential sales. In other words, the model should contain demand ceilings (upper limits). What is the optimal profit?
(b) The daily demands are strict obligations. In other words, the model should contain demand constraints that are met precisely. What is the optimal profit?
(c) The daily demands represent minimum sales commitments, but all output can be sold. In other words, the model should permit production to exceed the daily commitments. What is the optimal profit?
QUESTION
I've been able to construct the following model in Excel and solve it via OpenSolver, but I'm only able to integrate the mix for the Regular Oil.
I'm trying to work my way through the book Optimization Modeling with Spreadsheets by Kenneth R. Baker but I'm stuck with this exercise. While I could transfer the logic from another blending problem I'm not sure how to construct the model for multiple blendings at once.
I modeled the problem as a minimization problem on the cost of the different crude stocks. Using the Lubrication Index data I built the constraint for the R-Lub Index as a linear constraint. So far the answer seems to be right for the Regular Oil. However using this approach I've no idea how to include even the second Multigrade Oil.
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| Decision Variables | | | | | | | | |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| | C1 | C2 | C3 | C4 | | | | |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| Inputs | 1000 | 0 | 1000 | 0 | | | | |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| | | | | | | | | |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| Objective Function | | | | | | Total | | |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| Cost | 7,10 € | 8,50 € | 7,70 € | 9,00 € | | 14.800,00 € | | |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| | | | | | | | | |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| Constraints | | | | | | LHS | | RHS |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| C1 supply | 1 | | | | | 1000 | <= | 1000 |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| C2 supply | | 1 | | | | 0 | <= | 1100 |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| C3 supply | | | 1 | | | 1000 | <= | 1200 |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| C4 supply | | | | 1 | | 0 | <= | 1100 |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| R- Lub Index | -5 | 15 | 5 | 30 | | 0 | >= | 0 |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| R- Output | 1 | 1 | 1 | 1 | | 2000 | = | 2000 |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| | | | | | | | | |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| Blending Data | | | | | | | | |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| R- Lub | 20 | 40 | 30 | 55 | | 25 | >= | 25 |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
Here is the model with Excel formulars:
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| Decision Variables | | | | | | | | |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| | C1 | C2 | C3 | C4 | | | | |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| Inputs | 1000 | 0 | 1000 | 0 | | | | |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| | | | | | | | | |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| Objective Function | | | | | | Total | | |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| Cost | 7,1 | 8,5 | 7,7 | 9 | | =SUMMENPRODUKT(B5:E5;B8:E8) | | |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| | | | | | | | | |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| Constraints | | | | | | LHS | | RHS |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| C1 supply | 1 | | | | | =SUMMENPRODUKT($B$5:$E$5;B11:E11) | <= | 1000 |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| C2 supply | | 1 | | | | =SUMMENPRODUKT($B$5:$E$5;B12:E12) | <= | 1100 |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| C3 supply | | | 1 | | | =SUMMENPRODUKT($B$5:$E$5;B13:E13) | <= | 1200 |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| C4 supply | | | | 1 | | =SUMMENPRODUKT($B$5:$E$5;B14:E14) | <= | 1100 |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| R- Lub Index | -5 | 15 | 5 | 30 | | =SUMMENPRODUKT($B$5:$E$5;B15:E15) | >= | 0 |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| R- Output | 1 | 1 | 1 | 1 | | =SUMMENPRODUKT($B$5:$E$5;B16:E16) | = | 2000 |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| | | | | | | | | |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| Blending Data | | | | | | | | |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| R- Lub | 20 | 40 | 30 | 55 | | =SUMMENPRODUKT($B$5:$E$5;B19:E19)/SUMME($B$5:$E$5) | >= | 25 |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
A nudge in the right direction would be a tremendous help.
I think you want your objective to be Profit, which I would define as the sum of sales value - sum of cost.
To include all blends, develop calculations for Volume produced, Lube Index, Cost, and Value for each blend. Apply constraints for volume of stock used, volume produced, and lube index, and optimize for Profit.
I put together the model as follows ...
Columns A through D is the information you provided.
The 10's in G2:J5 are seed values for the stock volumes used in each blend. Solver will manipulate these.
Column K contains the total product volume produced. These will be constrained in different ways, as per your investigation (a), (b), and (c). It is =SUM(G3:J3) filled down.
Column L is the Lube Index for the product. As you noted, it is a linear blend - this is typically not true for blending problems. These values will be constrained in Solver. It is {=SUMPRODUCT(G3:J3,TRANSPOSE($B$2:$B$5))/$K3} filled down. Note that it is a Control-Shift-Enter (CSE) formula, required because of the TRANSPOSE.
Column M is the cost of the stock used to create the product. This is used in the Profit calculation. It is {=SUMPRODUCT(G3:J3,TRANSPOSE($C$2:$C$5))}, filled down. This is also a CSE formula.
Column N is the value of the product produced. This is used in the Profit calculation. It is =K3*C8 filled down.
Row 7 is the total stock volume used to generate all blends. These values will be constrained in Solver. It is =SUM(G3:G5), filled to the right.
The profit calculation is =SUM(N3:N5)-SUM(M3:M5).
Below is a snap of the Solver dialog box ...
It does the following ...
The objective is to maximize profit.
It will do this by manipulating the amount of stock that goes into each blend.
The first four constraints ($G$7 through $J$7) ensure the amount of stock available is not violated.
The next three constraints ($K$3 through $K$5) are for case (a) - make no more than product than there is demand.
The last three constraints ($L$3 through $L$5) make sure the lube index meets the minimum specification.
Not shown - I selected options for GRG Nonlinear and selected "Use Multistart" and deselected "Require Bounds on Variables".
Below is the result for case (a) ...
For case (b), change the constraints on Column K to be "=" instead of "<=". Below is the result ...
For case (c), change the constraints on Column K to be ">=". Below is the result ...
I think I came up with a solution, but I'm unsure if this is correct.
| Decision Variables | | | | | | | | | | | | | | | | |
|--------------------|---------|--------|--------|--------|-------------|--------|--------|--------|--------|--------|--------|--------|---|--------------------------------|----|------|
| | C1R | C1M | C1S | C2R | C2M | C2S | C3R | C3M | C3S | C4R | C4M | C4S | | | | |
| Inputs | 1000 | 0 | 0 | 800 | 0 | 300 | 0 | 1200 | 0 | 200 | 300 | 600 | | | | |
| | | | | | | | | | | | | | | | | |
| Objective Function | | | | | | | | | | | | | | Total Profit (Selling - Cost) | | |
| Cost | 7,10 € | 7,10 € | 7,10 € | 8,50 € | 8,50 € | 8,50 € | 7,70 € | 7,70 € | 7,70 € | 9,00 € | 9,00 € | 9,00 € | | 3.910,00 € | | |
| | | | | | | | | | | | | | | | | |
| Constraints | | | | | | | | | | | | | | LHS | | RHS |
| Regular | -5 | | | 15 | | | 5 | | | 30 | | | | 13000 | >= | 0 |
| Multi | | -15 | | | 5 | | | -5 | | | 20 | | | 0 | >= | 0 |
| Supreme | | | -30 | | | -10 | | | -20 | | | 5 | | 0 | >= | 0 |
| C1 Supply | 1 | 1 | 1 | | | | | | | | | | | 1000 | <= | 1000 |
| C2 Supply | | | | 1 | 1 | 1 | | | | | | | | 1100 | <= | 1100 |
| C3 Supply | | | | | | | 1 | 1 | 1 | | | | | 1200 | <= | 1200 |
| C4 Supply | | | | | | | | | | 1 | 1 | 1 | | 1100 | <= | 1100 |
| Regular Demand | 1 | | | 1 | | | 1 | | | 1 | | | | 2000 | >= | 2000 |
| Multi Demand | | 1 | | | 1 | | | 1 | | | 1 | | | 1500 | >= | 1500 |
| Supreme Demand | | | 1 | | | 1 | | | 1 | | | 1 | | 900 | >= | 750 |
| | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | |
| Selling | | | | | | | | | | | | | | | | |
| Regular | 8,50 € | x | 2000 | = | 17.000,00 € | | | | | | | | | | | |
| Multi | 9,00 € | x | 1500 | = | 13.500,00 € | | | | | | | | | | | |
| Supreme | 10,00 € | x | 900 | = | 9.000,00 € | | | | | | | | | | | |
| | | | | | 39.500,00 € | | | | | | | | | | | |

What does this nltk-boxer DRT output mean?

After much headache, I have finally managed to get Boxer and nltk boxer working. However, the output that I get from nltk boxer is somewhat different from what I was expecting. An example sentence like "Bob knows that John likes cows" should look like:
__________________ ____________________
|x1 x2 | |x3 x4 |
|..................| |....................|
(|named(x2,bob,per) |+|know(x3) |)
|named(x1,john,geo)| | Actor(x3,x2) |
|__________________| | Topic(x3,x4) |
| ______________ |
| |x5 x6 ||
| x4:|..............||
| |like(x5) ||
| | Actor(x5,x1)||
| | Theme(x5,x6)||
| |cow(x6) ||
| |______________||
|____________________|
But instead, it looks like:
_____________________
| e1 p1 x1 x2 |
|---------------------|
| ne_geo_john(x2) |
| ne_per_bob(x1) |
| Topic(e1,p1) |
| Actor(e1,x1) |
| v_know(e1) |
| ______________ |
| p1:| e2 x3 | |
| |--------------| |
| | Theme(e2,x3) | |
| | Actor(e2,x2) | |
| | v_like(e2) | |
| | n_cow(x3) | |
| |______________| |
|_____________________|
Why is that?

Resources