Pandas Series: to_clipboard() function
Series-to_clipboard() function
The to_clipboard() function is used to copy object to the system clipboard.
Write a text representation of object to the system clipboard. This can be pasted into Excel, for example.
Syntax:
Series.to_clipboard(self, excel=True, sep=None, **kwargs)
Parameters:
Name | Description | Type/Default Value | Required / Optional |
---|---|---|---|
excel | Indication of expected JSON string format.
|
bool, default True | Required |
sep | Field delimiter. | str, default '\t' | Required |
**kwargs | These parameters will be passed to DataFrame.to_csv. | Required |
Notes: Requirements for your platform.
- Linux : xclip, or xsel (with PyQt4 modules)
- Windows : none
- OS X : none
Example - Copy the contents of a DataFrame to the clipboard:
Python-Pandas Code:
import numpy as np
import pandas as pd
df = pd.DataFrame([[1, 2, 3], [4, 5, 6]], columns=['A', 'B', 'C'])
df.to_clipboard(sep=',')
# Wrote the following to the system clipboard:
# ,A,B,C
# 0,1,2,3
# 1,4,5,6
Example - We can omit the the index by passing the keyword index and setting it to false:
Python-Pandas Code:
import numpy as np
import pandas as pd
df = pd.DataFrame([[1, 2, 3], [4, 5, 6]], columns=['A', 'B', 'C'])
df.to_clipboard(sep=',', index=False)
# Wrote the following to the system clipboard:
# A,B,C
# 1,2,3
# 4,5,6
Previous: Series-to_json() function
Next: Series-to_latex() function
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/pandas/series/series-to_clipboard.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics