'Select nth rows every nth element in Python dataframe

I'm reading a .csv file, that has dates as index and states as columns.

Something like this:

enter image description here

The dates go from January 1950 to April 2022, I want to vary the slicing of the dataframe, for example I want to take all of the Januaries and Februaries (from 1950 to 2022) so it will look something like this

enter image description here

I know I can select every nth element with data.iloc[0::12], so I tried doing something like data.iloc[(0:1)::12] but it does not work.

How can I slice it the way I want it?

Thanks in advance



Solution 1:[1]

It seems iloc supports lambda function. So if you want your way:

df.iloc[lambda x:(x.index % 12).isin([0,1])]

However, it seems better to use str.startswith for your cases

df[df.index.str.startswith('Ene') | df.index.str.startswith('Feb')]

Solution 2:[2]

For your WMQ JCA configuration, you will need to add the section:

  <security>
       <elytron-enabled />
  </security>

So your configuration will look something like:

  <subsystem xmlns="urn:jboss:domain:resource-adapters:5.0">
     <resource-adapters>
         <resource-adapter id="wmq.jmsra.rar" statistics-enabled="true">
             <archive>
                 wmq.jmsra.rar
             </archive>
             <transaction-support>NoTransaction</transaction-support>
             <connection-definitions>
                 <connection-definition class-name="com.ibm.mq.connector.outbound.ManagedConnectionFactoryImpl" jndi-name="java:jboss/MQCF" tracking="false" pool-name="mq-pool">
                     <security>
                        <elytron-enabled />
                     </security>
                     <config-property name="channel">
                         CHANNEL
                     </config-property>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 NoThlnG
Solution 2 Doug Grove