Python | Pandas Series.to_clipboard()
Pandas series is a One-dimensional ndarray with axis labels. The labels need not be unique but must be a hashable type. The object supports both integer- and label-based indexing and provides a host of methods for performing operations involving the index.
Pandas Series.to_clipboard()
function copy object to the system clipboard. It write a text representation of object to the system clipboard. This can be pasted into Excel as well.
Syntax: Series.to_clipboard(excel=True, sep=None, **kwargs)
Parameter :
excel : bool, default True
sep : str, default ‘\t’
**kwargs : These parameters will be passed to DataFrame.to_csv.Returns : None
Example #1: Use Series.to_clipboard()
function to copy the given Series object to the systems clipboard.
# importing pandas as pd import pandas as pd # Creating the Series sr = pd.Series([ 'New York' , 'Chicago' , 'Toronto' , 'Lisbon' , 'Rio' , 'Moscow' ]) # Create the Datetime Index didx = pd.DatetimeIndex(start = '2014-08-01 10:00' , freq = 'W' , periods = 6 , tz = 'Europe/Berlin' ) # set the index sr.index = didx # Print the series print (sr) |
Output :
Now we will use Series.to_clipboard()
function to copy the given series object to the systems clipboard.
# copy to clipboard sr.to_clipboard() |
Output :
After executing the last line of code we simply pasted what was copied to the system’s clipboard in Notepad++. This is what it looks like.
Example #2: Use Series.to_clipboard()
function to copy the given Series object to the systems clipboard.
# importing pandas as pd import pandas as pd # Creating the Series sr = pd.Series([ 19.5 , 16.8 , None , 22.78 , None , 20.124 , None , 18.1002 , None ]) # Print the series print (sr) |
Output :
Now we will use Series.to_clipboard()
function to copy the given series object to the systems clipboard.
# copy to clipboard sr.to_clipboard() |
Output :
After executing the last line of code we simply pasted what was copied to the system’s clipboard in Notepad++. This is what it looks like. Notice how missing values has been represented as blanks.
Contact Us