Created
October 18, 2017 12:22
-
-
Save Jan-Zeiseweis/da08632d8061d939f52e4efe9679d534 to your computer and use it in GitHub Desktop.
Pandas create dataframe from clipboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
def clipboard_to_dataframe(): | |
""" | |
Parses tables in the format: | |
| Col1 | Col2 | | |
------------------- | |
| 1111 | abcdefgh | | |
| 2222 | abcdefgj | | |
------------------- | |
and returns a pandas.DataFrame | |
""" | |
return pd.read_clipboard(sep='[\s+|]+', | |
comment='-', | |
usecols=lambda col: not col.startswith('Unnamed'), | |
engine='python') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment