Change language

Python | Pandas Series.to_string ()

|

Series.to_string() Pandas Series.to_string() displays the string representation of the Series.

Syntax: Series.to_string (buf = None, na_rep = ’NaN’, float_format = None, header = True, index = True, length = False, dtype = False, name = False, max_rows = None)

Parameter:
buf: buffer to write to
na_rep: string representation of NAN to use, default ’NaN’
float_format: formatter function to apply to columns’ elements if they are floats default None
header : Add the Series header (index name)
index: Add index (row) labels, default True
length: Add the Series length
dtype: Add the Series dtype
name: Add the Series name if not None
max_rows: Maximum number of rows to show before truncat ing.

Returns: Formatted string.

Example # 1: Using Series.to_string () a function to render the string representation of a given series of objects.

# import pandas as pd

import pandas as pd

 
# Create series

sr = pd.Series ([ ’New York’ , ’ Chicago’ , ’Toronto’ , ’Lisbon’ , ’ Rio’ , ’Moscow’ ])

  
# Create date and time index

didx = pd.DatetimeIndex (start = ’2014-08-01 10:00 ’ , freq = ’ W’

periods = 6 , tz = ’Europe / Berlin’

  
# set index

sr.index = didx

  
# Print series

print (sr)

Output:

Now we will use Series.to_string () to render a string representation of this series object.

# render to inline form
sr.to_string ()

Output:

As we can see in the output, Series.to_string () has successfully rendered the string representation for the given object.

Example # 2: Use Series.to_string () to render the string representation of this series object.

# import pandas as pd

import pandas as pd

  
# Create series

sr = pd.Series ([ 19.5 , 16.8 , 22.78 , 20.124 , 18.1002 ])

 
# Print series

print (sr)

Output:

Now we we will use Series.to_string () to render a string representation of this series object.

# render to inline form
sr.to_string ()

Output:

Like us we can see in the output that Series.to_string () has successfully rendered the string representation for the given object.

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically