import pandas as pd
my_dict={
'NAME':['Ravi','Raju','Alex'],
'ID':[1,2,3],'MATH':[30,40,50],
'ENGLISH':[20,70,41]
}
df = pd.DataFrame(data=my_dict)
df.to_clipboard()
This is the data written to clipboard. We can paste the same in Excel file .
NAME ID MATH ENGLISH
0 Ravi 1 30 20
1 Raju 2 40 70
2 Alex 3 50 41
excel | Boolen ( default True ) Provide separator for pasting in Excel file, provide string if set to False |
sep | String, default is \t , The Field delimiters |
df.to_clipboard(index=False)
Output
NAME ID MATH ENGLISH
Ravi 1 30 20
Raju 2 40 70
Alex 3 50 41
df.to_clipboard(index=False,sep=',')
NAME,ID,MATH,ENGLISH
Ravi,1,30,20
Raju,2,40,70
Alex,3,50,41
df.to_clipboard(index=False,excel=False)
import mysql.connector
import pandas as pd
my_connect = mysql.connector.connect(
host="localhost",
user="root",
passwd="*****",
database="my_tutorial"
)
####### end of connection ####
sql="SELECT * FROM student limit 0,5"
df = pd.read_sql(sql,my_connect )
df.to_clipboard(index=False)
import pandas as pd
from sqlalchemy import create_engine
my_conn = create_engine("mysql+mysqldb://userid:pw@localhost/my_db")
sql="SELECT * FROM student LIMIT 0,10 "
df = pd.read_sql(sql,my_conn)
df.to_clipboard()
df=pd.read_excel("D:\\my_data\\student.xlsx") # Path of the file.
df.to_clipboard()
We can read one csv file by using read_csv()
df=pd.read_csv("D:\\my_data\\student.csv") # change the path
df.to_clipboard()
to_clipboard() method in pandas?to_clipboard() method to copy a DataFrame to the clipboard?to_clipboard() method?to_clipboard() method to copy a DataFrame to the clipboard?to_clipboard()?to_clipboard()?to_clipboard() method handle missing values in the DataFrame?to_clipboard() for copying data to the clipboard in pandas?to_clipboard() method interacts with the operating system's clipboard?to_clipboard()?Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.