Python Forum
Problem with date type (object to datetime)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with date type (object to datetime)
#7
edited: didnt see you reply before posting this :)

Ok this is what I've done so far and its working.

import pandas as pd
import datetime as dt
#from datetime import datetime 
import matplotlib.pyplot as plt
import numpy as np
import random, string

data = pd.read_csv('dec18_oct19.csv', sep = ';', header = None, low_memory = False)
data.head()
have this dataframe -> df
I don't really know what happened so that data[0].dtype became datetime64 type because since yesterday it was an object type !!!! and the reason of my post. lol

and then

#Because I just want to work with specific columns
dat = data[[0, 5, 6, 7, 8, 9, 10, 14, 15, 16]].copy(deep=False)
#dat[0] = pd.to_datetime(data[0], errors = 'coerce')
dat[5] = pd.to_numeric(dat[5], errors = 'coerce')
dat.head()
result -> slicing

now I can set the headers

dat.columns = [
'Date_Time',
'Netzspannung1', 
'Netzspannung2', 
'Netzspannung3', 
'Phasenstrom (Wirkstrom)1', 
'Phasenstrom (Wirkstrom)2', 
'Phasenstrom (Wirkstrom)3',
'Netzstrom1', 
'Netzstrom2', 
'Netzstrom3']
result -> final df

Is there any ideas to improve this. Thks
Reply


Messages In This Thread
RE: Problem with date type (object to datetime) - by karlito - Oct-16-2019, 08:07 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Numpy] Load date/time from .txt to 'datetime64' type. water 4 675 Mar-01-2024, 11:16 PM
Last Post: Gribouillis
  pymongo diff type problem to find images on two drives darter 0 1,298 Mar-11-2021, 04:52 AM
Last Post: darter
  replace nan values by mean group by date.year, date.month wissam1974 5 8,537 Feb-19-2020, 06:25 PM
Last Post: AnkitGupta
  Pandas and Date: problem with operator.How to resolve frame 6 4,405 May-13-2019, 05:50 PM
Last Post: frame
  TensorFlow problem in Object Detection yksingh1097 1 2,838 Oct-03-2018, 09:57 PM
Last Post: Larz60+
  Finding date count from a list of date range in pandas trillerducas72 0 2,766 May-24-2018, 02:30 AM
Last Post: trillerducas72

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020