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.

Python | Pandas Series.to_string () Python functions: Questions

Python | Pandas Series.to_string () String Variables: Questions

Shop

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

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method