[Tips] Easy-to-read writing when connecting functions in Python

I will introduce the writing method that I did not know & thought to imitate I think that you may execute many functions when performing data analysis or data preprocessing, but you can write the functions with line breaks by adding parentheses as shown below. I like this because it makes it easier to see.

import pandas as pd
from sklearn.datasets import load_iris
iris = load_iris()

(
data
.where(data['sepal length (cm)'] > 5)
.where(data['petal length (cm)'] > 5)
.sum()
)

that's all!

Recommended Posts

[Tips] Easy-to-read writing when connecting functions in Python
When writing a program in Python
Split files when writing vim plugin in python
A memorandum when writing experimental code ~ Logging in python
Overriding library functions in Python
Attention when os.mkdir in Python
Python functions learned in chemoinformatics
Convenient writing method when appending to list continuously in Python
[python] Manage functions in a list
Precautions when using pit in Python
LaTeX, Python tips in master's thesis
Behavior when listing in Python heapq
Using global variables in python functions
Dynamically define functions (methods) in Python
Reading and writing text in Python
[VS Code] ~ Tips when using python ~
When using regular expressions in Python
Settings when writing Google App Engine / Python apps in Intellij Idea
[Python ORM] Notation when writing SQL using subquery in IN clause in SQLAlchemy
Precautions when passing def to sorted and groupby functions in Python? ??
Don't forget shebang when writing Check! Ansible's Dynamic Inventory in python!
When specifying multiple keys in python sort
[Python3] Dynamically define global variables in functions
python tips
Create ScriptableObject in Python when building ADX2
Precautions when pickling a function in python
Easily use your own functions in Python
Tips for dealing with binaries in Python
Pharmaceutical company researchers summarized functions in Python
python tips
Python functions
What Emacs users should know when writing python code in Sublime Text
Template for writing batch scripts in python
When looking at memory usage in Python 3
New features in Python 3.4.0 (3)-Single-dispatch generic functions
Tips for making small tools in python
Python Tips
Python tips
Tips when amateurs use Flask in Visual Studio
When codec can't decode byte appears in python
When do python functions affect the caller's arguments?
Personal tips when doing various things with Python 3
When I try matplotlib in Python, it says'cairo.Context'
[CpawCTF] Q14. [PPC] Try writing Sort! In Python
A note on optimizing blackbox functions in Python
A memo about writing merge sort in Python
Precautions when dealing with control structures in Python 2.6
Reading and writing CSV and JSON files in Python
Tips for hitting the ATND API in Python
Note on encoding when LANG = C in Python
Practice applying functions and global variables in Python
The 18th offline real-time writing problem in Python
Character encoding when dealing with files in Python 3
Get files, functions, line numbers running in python
[Question] What happens when I use% in python?
Error when trying to install psycopg2 in Python
Behavior when saving python datetime object in MongoDB
Solution when module'XXX' has no attribute'XXX' in Python
The 19th offline real-time writing problem in Python
Use pydantic when reading environment variables in Python
Python Conda Tips