pandas.TimedeltaIndex.to_frame#
- TimedeltaIndex.to_frame(index=True, name=NoDefault.no_default)[源代码]#
创建一个DataFrame,其中包含索引的列。
- 参数
- index布尔值,默认为True
将返回的DataFrame的索引设置为原始索引。
- name对象,默认为无
传递的名称应该替换索引名称(如果它有索引名称)。
- 退货
- DataFrame
包含原始索引数据的DataFrame。
参见
Index.to_series
将索引转换为系列。
Series.to_frame
将系列转换为DataFrame。
示例
>>> idx = pd.Index(['Ant', 'Bear', 'Cow'], name='animal') >>> idx.to_frame() animal animal Ant Ant Bear Bear Cow Cow
默认情况下,会重复使用原始索引。要强制实施新索引,请执行以下操作:
>>> idx.to_frame(index=False) animal 0 Ant 1 Bear 2 Cow
若要覆盖结果列的名称,请指定 name :
>>> idx.to_frame(index=False, name='zoo') zoo 0 Ant 1 Bear 2 Cow