I have a column in my dataframe, which I want to convert to an acceptable date format, so that I can plot it using plotly.
I tried the following methods to get it to work, but I believe the input string is supposed to be in the same format. `
df['InsertedDate'] = pd.to_datetime(df['InsertedDate'], format='%Y%m%d')
df['InsertedDate'] = df['InsertedDate'].apply(lambda x: pd.to_datetime(str(x),format='%Y%m%d'))
My dataframe looks like this:
df = pd.DataFrame({'id': {0: 84, 1: 84, 2: 84, 3: 84, 4: 124},'commitDate': {0: '1617799976000',1: '1622430757000', 2: '1607286945000'}})
My original data is from MongoDB,which I exported in json, hence the numberLong format.
Any suggestions on how to perform this conversion?
CodePudding user response:
I believe unit='ms'
might be what you are looking for:
df['commitDate'] = pd.to_datetime(df['commitDate'], unit='ms')
df