Python | Pandas dataframe.to_clipboard()

Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.

Pandas dataframe.to_clipboard() function copy object to the system clipboard. This function writes a text representation of the object to the system clipboard. This could 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 : For link to the CSV file used in the code, click here



Example #1: Use to_clipboard() function to copy the object to the clipboard in a non-excel format.

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing pandas as pd
import pandas as pd
  
# Creating the dataframe 
df = pd.read_csv('nba.csv')
  
# Print the dataframe
df

chevron_right


Output :

Now we will copy this object to clipboard in a non-excel format.

filter_none

edit
close

play_arrow

link
brightness_4
code

# copy to clipboard
df.to_clipboard(excel = False, sep = ', ')

chevron_right


Output :

We have simply pasted, what got copied to the clipboard after executing the previous command. The software used was “Notepad++”.
 
Example #2: Use to_clipboard() function to copy the object to the clipboard in an excel format.

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing pandas as pd
import pandas as pd
  
# Creating the dataframe 
df = pd.read_csv('nba.csv')
  
# Print the dataframe
df

chevron_right


Output :

Now we will copy this object to clipboard in an excel format.

filter_none

edit
close

play_arrow

link
brightness_4
code

# copy to clipboard
df.to_clipboard(excel = True)

chevron_right


Output :

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.