【发布时间】:2018-07-05 02:01:58
【问题描述】:
我看到很多 DataFrames 发布到 StackOverflow,看起来像:
a dt b
0 -0.713356 2015-10-01 00:00:00 -0.159170
1 -1.636397 2015-10-01 00:30:00 -1.038110
2 -1.390117 2015-10-01 01:00:00 -1.124016
我还没有找到使用.read_clipboard(.read_table docs 中的参数列表)将这些复制到我的解释器的好方法。
我以为关键是parse_dates参数:
parse_dates : boolean or list of ints or names or list of lists or dict, default False
* boolean. If True -> try parsing the index.
* list of ints or names. e.g. If [1, 2, 3] -> try parsing columns 1, 2, 3 each as a separate date column.
* list of lists. e.g. If [[1, 3]] -> combine columns 1 and 3 and parse as a single date column.
* dict, e.g. {‘foo’ : [1, 3]} -> parse columns 1, 3 as date and call result ‘foo’
pd.read_clipboard(parse_dates={'dt': [1, 2]}) 引发异常 NotImplementedError: file structure not yet supported。
当我尝试跳过第一行 pd.read_clipboard(parse_dates=[[1, 2]], names=['a', 'dt1', 'dt2', 'b'], skiprows=1, header=None) 时,我得到了同样的异常。
其他人是怎么做到的?
【问题讨论】:
-
大量手动格式化,就我而言...
-
通常,各个列之间有两个空格。这使事情变得更容易。如果不是这样,你是 SOL,你必须自己做一些手动格式化。
标签: python pandas dataframe datetime clipboard