w3resource

Pandas: Create a DataFrame from the clipboard

Pandas: DataFrame Exercise-79 with Solution

Write a Pandas program to create a DataFrame from the clipboard (data from an Excel spreadsheet or a Google Sheet).

Sample Excel Data:

Python Exercises: Sample Excel data.

Sample Solution :

Python Code :

import pandas as pd
df = pd.read_clipboard()
print("Data from clipboard to DataFrame:")
print(df)

Sample Output:

Data from clipboard to DataFrame:
   1  2  3  4
0  2  3  4  5
1  4  5  1  0
2  2  3  7  8

Python Code Editor:


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Pandas program to replace the current value in a dataframe column based on last largest value. If the current value is less than last largest value replaces the value with 0.
Next: Write a Pandas program to check for inequality of two given DataFrames.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

Dictionary comprehension:

>>> m = {x: x ** 2 for x in range(5)}
>>> m
{0: 0, 1: 1, 2: 4, 3: 9, 4: 16}