【发布时间】:2019-04-19 02:28:30
【问题描述】:
我有这个列标题:
我将这些放在x = list(df) 的列表中,x 的类型是一个字符串。我想将它们放入另一个字符串列表中,但将它们转换为 8/18、7/18、6/18 等...
这里是 df.head() 输出:
print(df.columns)的输出
<class 'str'>
Index(['NDD 8/31', 'Aug 2018(P&I Applied)', 'Jul 2018(P&I Applied)',
'Jun 2018(P&I Applied)', 'May 2018(P&I Applied)',
'Apr 2018(P&I Applied)', 'Mar 2018(P&I Applied)',
'Feb 2018(P&I Expected)', 'Jan 2018(P&I Applied)',
'Dec 2017(P&I Applied)', 'Nov 2017(P&I Applied)',
'Oct 2017(P&I Applied)', 'Sep 2017(P&I Applied)',
'Paystring as of cut off as if 10.31',
'Paystrings as of
有谁知道如何做到这一点?
【问题讨论】:
-
能否将 print(df.columns) 的输出添加到问题中?
-
@ScottBoston 添加
-
您想只替换
Jun 2018 -> 6/18,还是应该将整个列名替换为6/18? -
@MatthiasOssadnik 不,我不需要修改数据框,我只想转换 Jun 2018 -> 6/18 并将其放入向量或列表中
标签: python pandas datetime dataframe indexing