Skip to content
Related Articles

Related Articles

Improve Article

Python | Pandas dataframe.to_clipboard()

  • Last Updated : 29 Jan, 2019

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.




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

Output :

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




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

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.




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

Output :

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




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

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. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :