Cln/separate logic from init
- [ ] closes #xxxx (Replace xxxx with the GitHub issue number)
- [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature
- [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit).
- [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions.
- [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.

I'm new to the project and was trying to contribute in some way.
To do this, I ran some static analysis tools(sonarcube, pylint and flake8).
I am now aiming to improve readability and maintainability by proposing a quality improvement that involves removing code duplication and transforming it into a function.
Hi thanks for the suggestion, I will have a think on this. Im not convinced that this really reduces code duplication. You have taken a few one line functions and turned it into more code that still calls one line functions.

There are probably many areas which could benefit from this kind of analysis though, maybe just not here. Hi @attack68, thank you for your reply. I understood what you said. I noticed a pattern of using lambda functions repetitively without treating them as functions in other parts of the pandas code; this is probably more of a code style to simplify things.

The two warning code pylint gave me are [C3001](https://pylint.pycqa.org/en/latest/user_guide/messages/convention/unnecessary-lambda-assignment.html) and [W0108](https://pylint.readthedocs.io/en/stable/user_guide/messages/warning/unnecessary-lambda.html).

I can define a function to be used during the initialization of the class; this approach might be cleaner than before. What do you think? Thanks for the PR but I also agree I don't think this change is necessarily an improvement here.

Closing, but happy to have your contributions to any issue labeled `good first issue`