sep=''
in the context of a function call sets the named argument sep
to an empty string. See the print[]
function; sep
is the separator used between multiple values when printing. The default is a space [sep=' '
], this function call makes sure that there is no space between Property tax: $
and the formatted tax
floating point value.
Compare the output of the following
three print[]
calls to see the difference
>>> print['foo', 'bar']
foo bar
>>> print['foo', 'bar', sep='']
foobar
>>> print['foo', 'bar', sep=' -> ']
foo -> bar
All that changed is the sep
argument value.
\t
in a string literal is an escape sequence for tab character, horizontal whitespace, ASCII codepoint 9.
\t
is easier to read and type than the actual tab character. See the table of
recognized escape sequences for string literals.
Using a space or a \t
tab as a print separator shows the difference:
>>> print['eggs', 'ham']
eggs ham
>>> print['eggs', 'ham', sep='\t']
eggs ham
Escape Codes: \b, \t, \n, \a, \r
s = "e:\\Beginner" s1 = "e:" "\\" "Beginner" s2 = s1 + \ "\\tst.py" print "This is a DOS path:", s print "This is a DOS path:", s1 print "This is a DOS path:", s2 s3 = "I contain 'single' quotes" print s3 s6 = "I contain\t\t\tthree\t\t\ttabs" s7 = "I contain a\t\v\tvertical tab" s8 = "I contain a\t\a\tBELL, which you can hear" print s6 print s7 print s8 s9 = "I contain a BACK\bSPACE" s10 = "I contain a BACKK\bSPACE AND a \nNEWLINE and a \rLINEFEED" s11 = "I ve got a FORM\fFEED!" print s9 print s10 print print s11 s12 = "If Python doesn't know what the escape code\n" \ "means, it performs the identity operation! \identity!" s13 = "But if you don't know what a code means, don't use it!" print s12 print s13
Related examples in the same category
1. | Escape characters: \n and \t | ||
2. | Demonstrates the use of quotes in strings | ||
3. | String escape sequences Demo |
Escape Characters
To insert characters that are illegal in a string, use an escape character.
An escape character is a backslash \
followed by the character you want to insert.
An example of an illegal character is a double quote inside a string that is surrounded by double quotes:
Example
You will get an error if you use double quotes inside a string that is surrounded by double quotes:
txt = "We are the so-called "Vikings" from the north."
Try it Yourself »
To fix this problem, use the escape character \"
:
Example
The escape character allows you to use double quotes when you normally would not be allowed:
txt = "We are the so-called \"Vikings\" from the north."
Try it Yourself »
Other escape characters used in Python:
\' | Single Quote | Try it » |
\\ | Backslash | Try it » |
\n | New Line | Try it » |
\r | Carriage Return | Try it » |
\t | Tab | Try it » |
\b | Backspace | Try it » |
\f | Form Feed | |
\ooo | Octal value | Try it » |
\xhh | Hex value | Try it » |
View Discussion Improve Article Save Article View Discussion Improve Article Save Article pandas.DataFrame.T property is used to transpose index and columns of the data frame. The property T is somehow related to
method transpose[]. The main function of this property is to create a reflection of the data frame overs the main diagonal by making rows as columns and vice versa. Syntax: DataFrame.T Parameters: Returns: The Transposed data frame Example
1: Sometimes we need to transpose the data frame in order to study it more accurately. In this situation pandas.DataFrame.T property plays an important role.
copy: If True, the underlying data is copied, otherwise [default].
*args, **kwargs: Additional keywordsPython3
import
pandas as pd
dit
=
{
'August'
: [
10
,
25
,
34
,
4.85
,
71.2
,
1.1
],
'September'
: [
4.8
,
54
,
68
,
9.25
,
58
,
0.9
],
'October'
: [
78
,
5.8
,
8.52
,
12
,
1.6
,
11
],
'November'
: [
100
,
5.8
,
50
,
8.9
,
77
,
10
]}
df
=
pd.DataFrame[data
=
dit]
df
Output:
Transposing the data frame.
Python3
df_trans
=
df.T
print
[
"Transposed Data frame :"
]
df_trans
Output:
In the above example, we transpose the data frame ‘df’ having numeric values/content.
Example 2:
Python3
import
pandas as pd
data
=
[[
'Harvey.'
,
10.5
,
45.25
,
95.2
],
[
'Carson'
,
15.2
,
54.85
,
50.8
],
[
'juli'
,
14.9
,
87.21
,
60.4
],
[
'Ricky'
,
20.3
,
45.23
,
99.5
],
[
'Gregory'
,
21.1
,
77.25
,
90.9
],
[
'Jessie'
,
16.4
,
95.21
,
10.85
]]
df
=
pd.DataFrame[data, columns
=
[
'Name'
,
'Age'
,
'Percentage'
,
'Accuracy'
],
index
=
[
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
]]
df
Output:
Transposing the dataframe.
Python3
df_trans
=
df.T
print
[
"Transposed Data frame :"
]
df_trans
Output:
In the above example, we transpose the data frame ‘df’ having mixed up data type.