简体   繁体   中英

How can I convert a table that have being copy-pasted to a pandas DataFrame?

How can I convert a table that have being copy-pasted to a pandas DataFrame?

As an example, I have the following table that have being copy-pasted:

Step    Training Loss   Validation Loss
5000    8.524000    6.308433
10000   6.043500    5.703260
15000   5.556500    5.274880
20000   5.203900    4.956189
25000   4.925100    4.714767
30000   4.708400    4.511205
35000   4.541200    4.338839
40000   4.380300    4.211163
45000   4.262100    4.087589
50000   4.154100    3.984569
55000   4.060400    3.890067
60000   3.965400    3.807854
65000   3.894100    3.728049
70000   3.814200    3.654750
75000   3.754300    3.597961
80000   3.695300    3.534978
85000   3.644300    3.490259
90000   3.595700    3.439605
95000   3.545500    3.385926
100000  3.496100    3.351504
105000  3.461700    3.298338
110000  3.418300    3.278054

Some suggested to use pd.read_clipboard(sep=sep=r'\s{2,}', engine='python') which is nice. But it didn't work for me because I was working on a Virtual Machine at Google Cloud Platform. So I've copy-pasted the table into a text editor, saved as csv and opened it using read_csv("file.csv", sep="\t") .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM