Skip to content

Instantly share code, notes, and snippets.

@Jan-Zeiseweis
Created October 18, 2017 12:22
Show Gist options
  • Save Jan-Zeiseweis/da08632d8061d939f52e4efe9679d534 to your computer and use it in GitHub Desktop.
Save Jan-Zeiseweis/da08632d8061d939f52e4efe9679d534 to your computer and use it in GitHub Desktop.
Pandas create dataframe from clipboard
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