本文介绍了使用pd.read_clipboard读取漂亮打印/格式化的数据框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是另一个的数据框:

Here's a dataframe from another question:

+--------------------+---------------+-------+
|   Location         | Date          | Value |
+--------------------+---------------+-------+
| India              | 2015-03-15    |   -200|
| India              | 2015-02-15    |  140  |
| India              | 2015-01-15    |  155  |
| India              | 2015-12-15    |   85  |
| India              | 2015-11-15    |   45  |
| China              | 2015-03-15    |   199 |
| China              | 2015-02-15    |  164  |
| China              | 2015-01-15    |  209  |
| China              | 2015-12-15    |   24  |
| China              | 2015-11-15    |   11  |
| Russia             | 2015-03-15    |   48  |
| Russia             | 2015-02-15    |  104  |
| Russia             | 2015-01-15    |  106  |
| Russia             | 2015-12-15    |   -20 |
| Russia             | 2015-11-15    |   10  |
+--------------------+---------------+-------+

为方便起见,以下是您可以毫无问题复制的版本:

And, for the sake of convenience, here's the version that you can copy without any problems:

   Location        Date  Value
0     India  2015-03-15   -200
1     India  2015-02-15    140
2     India  2015-01-15    155
3     India  2015-12-15     85
4     India  2015-11-15     45
5     China  2015-03-15    199
6     China  2015-02-15    164
7     China  2015-01-15    209
8     China  2015-12-15     24
9     China  2015-11-15     11
10   Russia  2015-03-15     48
11   Russia  2015-02-15    104
12   Russia  2015-01-15    106
13   Russia  2015-12-15    -20
14   Russia  2015-11-15     10

df中如何阅读.read_clipboard 无需手动删除所有这些定界符和行分隔符?

How would you read it in using df.read_clipboard without having to manually remove all those delimiters and row separators?

使用<$ c $可以很容易c> sep 或定界符(如果不是用于 --- + ----

This would've been easy using sep or delimiter if it were not for the ---+----.

推荐答案

In [129]: pd.read_clipboard(comment='+', sep='\s*\|\s*', usecols=[1,2,3], engine='python')
Out[129]:
   Location        Date  Value
0     India  2015-03-15   -200
1     India  2015-02-15    140
2     India  2015-01-15    155
3     India  2015-12-15     85
4     India  2015-11-15     45
5     China  2015-03-15    199
6     China  2015-02-15    164
7     China  2015-01-15    209
8     China  2015-12-15     24
9     China  2015-11-15     11
10   Russia  2015-03-15     48
11   Russia  2015-02-15    104
12   Russia  2015-01-15    106
13   Russia  2015-12-15    -20
14   Russia  2015-11-15     10

这篇关于使用pd.read_clipboard读取漂亮打印/格式化的数据框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 05:25