Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
206 views
in Technique[技术] by (71.8m points)

python - How to convert a datetime.datetime objet to a float?

I have a dataframe with to columns looking like this:

        c1.1                        c1.2
    2019-11-01 00:15:00+01:00   1260.00304232804
    2019-11-01 00:30:00+01:00   402.552212643678
    2019-11-01 00:45:00+01:00   524.666157608132
    2019-11-01 01:00:00+01:00   476.758148148148
    2019-11-01 01:15:00+01:00   492.47544534413

I would like to convert both to floats. I have tried using df['c1.1'].astype(float), however, this does not work due to the first column being datetime.datetime. I get the following error: float() argument must be a string or a number, not 'datetime.datetime'

I've also tried converting both columns to strings, before turning them into floats, but this is also not working. Error: could not convert string to float: '2019-11-01 00:15:00+01:00'

Does anyone know how to solve this problem? Thank you!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...