dataframeunix-timestampstrsplitdata-preprocessinginformation-extraction

Python Extracting numeric value from {'$date': {'$numberLong': 'xxxxxxxxxxxxxx'}}


I am having trouble extracting a numeric value from a pandas DF column. I have a data frame converted from Json and it contains column values like Image "1";

Image 1

As you can imagine the thing I need is unix timestamp values from this 'dict'. While type of this spesific column is pandas.core.series.Series, values are listed as 'dict'. I am looking for a more general approach to this problem since I also have other columns formated this way like Image2 ;

Image2

So far I tried numerous .read commands with spesific delimeters. I tried casting dict into other formats, converting df part to a list and many other things I cant even recall.

Thank you in advance. Have a good day.


Solution

  • Ok so I casted dic into str with;

    df_date = pd.DateFrame() df_date['TimeStamp'] = df['TimeStamp'].astype(str)

    and then;

    df_date = df['TimeStamp'].str.split("'", expand=True) ## ("'" is delimiter identification and ' is my target delimiter)

    this code above gave me a data frame with 6 columns, column no:5 was my expected UnixTimeStamp values so I replaced it with the original df column with this;

    df['Date'] = df_date[5]

    this solved my problem.