read_clipboard() Read Clipboard data to create DataFrame

import pandas as pd 
df = pd.read_clipboard() # reading from your clipboard 
print(df)

Visit this Page about DataFrame and copy the first output table using your mouse.
After copying just run the above code.

Output is here ( This depends on what you have copied.)
   NAME  ID  MATH  ENGLISH
0  Ravi   1    30       20
1  Raju   2    40       30
2  Alex   3    50       40
read_clipboard(): Read the clipboad data and create DataFrame #B12

Parameters

sep : By default space is used as separator, we can specify any string or regex delimiter.
engine : Change the default engine if you are getting this error.

Using sep and engine

To copy Functions with Descripitions from the PHP manual here we have to use different delimiter as space is not used here.
df=pd.read_clipboard(sep='—',engine='python')

Storing data in CSV or Excel file

We can store the output in csv file by using to_csv() or by using Excel file.
import pandas as pd 
df = pd.read_clipboard()
print(df) 
df.to_csv('D:\my_clipboard.csv')# path with file name to store 
Next time by using your mouse select data in any web page ( url ) or excel file or any other Tabular data. Run the above code and take your CSV or Excel file from D drive ( or location of your choice ) .

Creating HTML page by using to_html()

We can use the clipboard data to create HTML tables and save the file as web page or in .html format by using to_html(). Here is the code.
import pandas as pd 

df = pd.read_clipboard()
print(df)
df.to_html('D:\my_html.html') # change the path to store 
HTML file using Clipboard data
The above code will create my_html.html file at D Drive ( change the location if you want ) . The source code of this file is here
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>NAME</th>
      <th>ID</th>
      <th>MATH</th>
      <th>ENGLISH</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>Ravi</td>
      <td>1</td>
      <td>30</td>
      <td>20</td>
    </tr>
    <tr>
      <th>1</th>
      <td>Raju</td>
      <td>2</td>
      <td>40</td>
      <td>30</td>
    </tr>
    <tr>
      <th>2</th>
      <td>Alex</td>
      <td>3</td>
      <td>50</td>
      <td>40</td>
    </tr>
  </tbody>
</table>

Python Pandas reading data from Clipboard and create DataFrame by using read_clipboard()


read_csv()

Data input and output from Pandas DataFrame
Pandas to_clipboard() read_excel() to_csv() to_excel()
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer