无法将字符串格式的日期转换为datetime对象

时间:2019-04-15 05:49:24

标签: python

我有一个要转换为日期时间的列日期,因此我可以从这些值中提取月份。但是,并非所有值都已正确转换,我无法理解其原因。 比较样本中的第一和第二至第三值。

日期格式为DD-MM-YYYY

这是我尝试过的。

这是我要转换的值

05-02-2019
07-03-2019
18-03-2019
13-02-2019
05-03-2019

sample['Date'] = pd.to_datetime(sample.date)

sample

2 个答案:

答案 0 :(得分:3)

只需指定format

pd.to_datetime(sample['date'], format='%d-%m-%Y')

答案 1 :(得分:0)

尝试使用$user = $_SESSION['login_user']; if(isset($user) && $user != ''){ $query = "SELECT * from adminlogin where email = '$user'"; $ses_sql = mysqli_query($conn, $query); $row = mysqli_fetch_assoc($ses_sql); $login_session = $row['nom']; $login_session2 = $row['id']; $login_session3 = $row['motdepasse']; }else{ header("location:index.php"); } 方法。 例如:

both(kill -9, -15)

%A-将为您提供工作日 %B-月名称 %d-每月的某天 %Y-将给您年份