小编pyt*_*ter的帖子

Python - 从Datetime字符串中删除时间

我有一个日期字符串,并希望将其转换为日期类型:

我试图使用datetime.datetime.strptime和我想要的格式,但它返回转换的时间.

    when = alldates[int(daypos[0])]
    print when, type(when)

    then = datetime.datetime.strptime(when, '%Y-%m-%d')
    print then, type(then)
Run Code Online (Sandbox Code Playgroud)

这是输出返回的内容:

   2013-05-07 <type 'str'>
   2013-05-07 00:00:00 <type 'datetime.datetime'>
Run Code Online (Sandbox Code Playgroud)

我需要删除时间:00:00:00.

python datetime strptime python-2.7

32
推荐指数
3
解决办法
8万
查看次数

将SKLearn癌症数据集加载到Pandas DataFrame中

我正在尝试根据键(target_names,target和DESCR)加载sklearn.dataset并丢失一列.我已经尝试了各种方法来包含最后一列,但有错误.

 import numpy as np
 import pandas as pd
 from sklearn.datasets import load_breast_cancer

 cancer = load_breast_cancer()
 print cancer.keys()
Run Code Online (Sandbox Code Playgroud)

键是['target_names','data','target','DESCR','feature_names']

 data = pd.DataFrame(cancer.data, columns=[cancer.feature_names])
 print data.describe()
Run Code Online (Sandbox Code Playgroud)

使用上面的代码,它只返回30列,当我需要31列.将scikit-learn数据集加载到pandas DataFrame中的最佳方法是什么.

python numpy scikit-learn

9
推荐指数
2
解决办法
1万
查看次数

标签 统计

python ×2

datetime ×1

numpy ×1

python-2.7 ×1

scikit-learn ×1

strptime ×1