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-Pandas 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 Programming skills with w3resource's quiz.



Share this Tutorial / Exercise on : Facebook and Twitter

Python: Tips of the Day

Join Strings in an Iterable:

>>> words = ('Hello', 'Python', 'Programmers')
>>> '!'.join(words)
'Hello!Python!Programmers'
>>> words_dict = {0: 'zero', 1: 'one', 2: 'two', 3: 'three'}
>>> '&'.join(words_dict.values())
'zero&one&two&three'