w3resource

Pandas: Create a DataFrame from the clipboard


79. Create DataFrame from Clipboard

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

For more Practice: Solve these Related Problems:

  • Write a Pandas program to read data from the clipboard and then convert it into a DataFrame with custom column headers.
  • Write a Pandas program to import tabular data from the clipboard and then display its summary statistics.
  • Write a Pandas program to capture data from the clipboard, create a DataFrame, and then filter rows based on a condition.
  • Write a Pandas program to read clipboard data into a DataFrame and then export it to a CSV file with a specified delimiter.

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.



Follow us on Facebook and Twitter for latest update.