Here is my dataframe:
In [1]: import pandas as pd
In [2]: df = pd.DataFrame({'col1':['A','A','A','B','B','B'], 'col2':['C','D','D','D','C','C'],
'col3':[.1,.2,.4,.6,.8,1]})
In [3]: df
Out[4]:
col1 col2 col3
0 A C 0.1
1 A D 0.2
2 A D 0.4
3 B D 0.6
4 B C 0.8
5 B C 1.0
My question is: When I want to wrap the long text, where shall I put the backslash? After the dot or before the dot? Which is correct?
# option 1 backslash after dot or comma
df.groupby('col1').\
sum()
df['col1'],\
df['col2']
# option 2 backslash before dot or comma
df.groupby('col1')\
.sum()
df['col1']\
,df['col2']
I also find that if I use parentheses I do not have to use the backslash. Then which option is correct?
# option 1: no backslash and dot or comma in the new line
(df.groupby('col1')
.sum())
(df['col1']
,df['col2'])
# option 2: no backslash and dot or comma in the old line
(df.groupby('col1').
sum())
(df['col1'],
df['col2'])
# option 3: backslash after dot or comma
(df.groupby('col1').\
sum())
(df['col1'],\
df['col2'])
# option 4: backslash before dot or comma
(df.groupby('col1')\
.sum())
(df['col1']\
,df['col2'])