Python Panda数据框将非数字值转换为数字

时间:2019-04-28 09:01:30

标签: python pandas dataframe

MY panda数据帧具有字符串,日期时间和整数列值。如何将完整的数据框转换为数字(不影响现有的数字列)

1 个答案:

答案 0 :(得分:0)

基本上,我需要您的确切数据。但是,我只写下了一些示例,如下所示:

import pandas as pd
df = pd.DataFrame()
df['Date'] = ['6/24/2019','6/14/2019','2019-09-06 00:00:00','6/14/2019','6/14/2019']
df['newDate'] = pd.to_datetime(df['Date'])
print (df)

结果如下:

                  Date    newDate
0            6/24/2019 2019-06-24
1            6/14/2019 2019-06-14
2  2019-09-06 00:00:00 2019-09-06
3            6/14/2019 2019-06-14
4            6/14/2019 2019-06-14

例如,数据如下:

df['Date'] = [6/24/2019,
              6/14/2019,
              2019-09-06 00:00:00,
              6/14/2019,
              6/14/2019]