In addition to Dan's answer, you can apply line wrapping for all cells (code or markdown) by specifying the top object as Cell. Adding the code below to your ~/.jupyter/nbconfig/notebook.json
This may not be as satisfactory of an answer but while working Google Colab, I use the three single quote marks above and below the line of comments. Once quote marks are in place, I can hit return where I see fit.
Original comment:
# Using the number of rows from the original concatenated dataframe and the trimmed dataframe, quantify the percent difference between the number of rows lost
Solution:
Using the number of rows from the original concatenated dataframe and the
trimmed dataframe, quantify the percent difference between the number of
rows lost
'''
I am working with Jupyter notebook (.ipynb) through VSC Visual Studio Code, and I did find out that setting line/word wrapping could be set as follows:
hit F1
choose Preferences: Open Settings (UI)
start typing in wrap
Editor: Word Wrap Controls how lines should wrap pops up, change to On
It works for code (Python cells). Markdown cells work fine even without changing above setting.
Easiest for me was this, straightforward and does not require a pip install:
from textwrap import wrap
long_str = 'I rip wrap unravel when I time travel, with beats in my head'
lines = wrap(long_str, 20) #wrap outputs a list of lines
print('\n'.join(lines)) #so join 'em with newline
#prints:
#I rip wrap unravel
#when I time travel,
#with beats in my
#head
Since none of these solutions worked for me, I opted for a different approach and wrote a simple column-wrapping print function that you can use to manually guarantee that the lines of any string will remain in view, for simple output checking scenarios.
def printwr( item, wrapCol=70 ):
""" wrap printing to column limit """
posit = 0
while True:
# if remaining legnth eq/less than wrapCol, print and rturn
if len(item[posit:]) <= wrapCol: print(item[posit:]); return
# else take wrapCol chars from last index
llim = posit+wrapCol+1
# if more than one item, drop last contiguous non-space sequence (word)
lineSpl = item[posit:llim].split(' ')
segment = ' '.join(lineSpl[:-1]) if len(lineSpl)>1 else lineSpl
# print segment and increment posit by length segment
posit += len(segment)+1
print(segment)
For example, for
exampleStr = "populations tend to cluster in the foothills and periphery of the rugged Hindu Kush range; smaller groups are found in many of the country's interior valleys; in general, the east is more densely settled, while the south is sparsely populated"
printwr(exampleStr)
produces:
populations tend to cluster in the foothills and periphery of the
rugged Hindu Kush range; smaller groups are found in many of the
country's interior valleys; in general, the east is more densely
settled, while the south is sparsely populated