Я использую этот класс, чтобы представить DataFrames в файле .ipynb: < /p>
# Handy class for DataFrame viz
class display(object):
'''
Display HTML representation of multiple objects
'''
template = '''
{0}
{1}
'''
def __init__(self, *args):
self.args = args
def _repr_html_(self):
return '\n'.join(self.template.format(a, eval(a)._repr_html_()) for a in self.args)
def __repr__(self):
return '\n\n'.join(a + '\n' + repr(eval(a)) for a in self.args)
< /code>
Этот класс не работает внутри блока if-else, и я не понимаю, почему. < /p>
Может ли кто-нибудь дать объяснение? Спасибо заранее!import pandas as pd
# Handy class for DataFrame viz
# Create a sample DataFrame with 3 rows and 5 columns
df = pd.DataFrame({
'A': [1, 2, 3],
'B': [4, 5, 6],
'C': [7, 8, 9],
'D': [10, 11, 12],
'E': [13, 14, 15]
})
# Display the DataFrame
display('df')
>>>
df
A B C D E
0 1 4 7 10 13
1 2 5 8 11 14
2 3 6 9 12 15
< /code>
inside = True
if inside:
display('df')
>>>
Подробнее здесь: https://stackoverflow.com/questions/760 ... r-notebook