WPF ItemsControl the current ListItem Index in the ItemsSource

I asked the same thing a while ago here There isn’t a built in Index property, but you can set the AlternationCount of your ItemsControl to something higher than your item count, and bind to the AlternationIndex <TextBlock Text=”{Binding Path=(ItemsControl.AlternationIndex), RelativeSource={RelativeSource Mode=TemplatedParent}, FallbackValue=FAIL, StringFormat={}Index is {0}}” /> It should be noted that this solution may … Read more

What’s the alternative to pandas chain indexing?

Use multi-axis indexing, e.g. df.loc[‘a’, ‘1’] When you use df[‘1’][‘a’], you are first accessing the series object s = df[‘1’], and then accessing the series element s[‘a’], resulting in two __getitem__ calls, both of which are heavily overloaded (handle a lot of scenarios, like slicing, boolean mask indexing, and so on). It’s much more efficient … Read more

How to efficiently assign unique ID to individuals with multiple entries based on name in very large df

This approach uses .groupby() and .ngroup() (new in Pandas 0.20.2) to create the id column: df[‘id’] = df.groupby([‘LastName’,’FirstName’]).ngroup() >>> df First Second id 0 Tom Jones 0 1 Tom Jones 0 2 David Smith 1 3 Alex Thompson 2 4 Alex Thompson 2 I checked timings and, for the small dataset in this example, Alexander’s … Read more