Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
214 views
in Technique[技术] by (71.8m points)

python - Copy markdown formatted tables from SO to pandas clipboard

I am comfortable in using pd.read_clipboard() when the data posted on SO has spaces between columns ('ss+')

However, how would one copy the below table directly to a pandas dataframe?

Record ID Shared On
(UNIX timestamp)
Share type Share To User
1 1611872850 shared user A
2 1611872851 shared user B
3 1611872852 shared user B
1 1611872853 share_removed user A
question from:https://stackoverflow.com/questions/65947246/copy-markdown-formatted-tables-from-so-to-pandas-clipboard

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Looks like

pd.read_clipboard(sep='s*|s*').iloc[1:,1:-1]

works pretty well. Output:

  Record ID Shared On<br/>(UNIX timestamp)     Share type Share To User
1         1                     1611872850         shared        user A
2         2                     1611872851         shared        user B
3         3                     1611872852         shared        user B
4         1                     1611872853  share_removed        user A

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...