Change language

Python | Pandas dataframe.to_clipboard ()

|

The Pandas function dataframe.to_clipboard() copies the object to the system clipboard. This function writes the textual representation of the object to the system clipboard. This can be easily pasted into Excel or Notepad ++.

Syntax: DataFrame.to_clipboard (excel = True, sep = None, ** kwargs)

Parameters:
excel: True, use the provided separator, writing in a csv format for allowing easy pasting into excel. False, write a string representation of the object to the clipboard.
sep: Field delimiter.
** kwargs: These parameters will be passed to DataFrame.to_csv.

Note: to link to the CSV file used in the code, click here

Example # 1: Use to_clipboard () to copy the object to the clipboard in the format, to_clipboard () Excel.

# import pandas as pd

import pandas as pd

 
# Create data frame

df = pd.read_csv ( ’nba.csv’ )

  
# Print the data frame
df

Output:

We will now copy this object to the clipboard in a non-Excel format.

# copy to clipboard

df.to_clipboard (excel = False , sep = ’,’ )

Output:

We just pasted what was copied to the clipboard after the previous command. Notepad ++ software was used.

Example # 2: Use to_clipboard () to copy the object to the clipboard in Excel format.

# import pandas as pd

import pandas as pd

  
# Create a data frame

df = pd.read_csv ( ’nba.csv’ )

  
# Print the data frame
df

Output:

Now we will copy this object to the clipboard in Excel format.

# copy to clipboard

df.to_clipboard (excel = True )

Output:

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

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