This is a rather interesting feature in pandas. Any tabular data that has been copied onto the clipboard can be read as a DataFrame in pandas.
Let's copy the following tabular data with the usual ctrl + C keyboard command:
Gender |
Entry_Date |
Flag |
|
A |
M |
2012-01-19 |
True |
B |
F |
2012-12-30 |
False |
C |
M |
2012-05-05 |
False |
Calling the read_clipboard() function makes this data available as a pandas DataFrame:
pd.read_clipboard()
Take a look at the following output:
![](https://static.packt-cdn.com/products/9781789343236/graphics/assets/9479c71d-b380-484b-9e00-c217d19a956f.png)
Output of read_clipboard
This function also recognizes the Flag column as a bool data type by default and assigns the unnamed column to be the index:
![](https://static.packt-cdn.com/products/9781789343236/graphics/assets/8ab745a9-7b80-4af3-bd88-83f89e40fe90.png)
Data types after reading the clipboard