See the example below. Is it possible to put each Python operation on a new line? If I have many operations, the code is not all visible. I need to scroll the VS Code window to the right. Thanks
JavaScript
x
8
1
# R code
2
data %>%
3
group_by(sex) %>%
4
summarise(avg_height=mean(height))
5
6
# Python code
7
data.groupby(['sex']).agg(avg_height=('height', 'mean')).reset_index()
8
Advertisement
Answer
In Python, line breaks inside parentheses are ignored, so you could rewrite as:
JavaScript
1
5
1
(data
2
.groupby(['sex'])
3
.agg(avg_height=('height', 'mean'))
4
.reset_index())
5
This post may be helpful.