Twitter’s “CREATED_AT” format looks something like this Wed Mar 04 02:14:57 +0000 2015
. To convert this to Python’s datetime
format, simply use datetime.strptime()
. If the tweets are stored in a pandas
data frame, you may use the following code below to “fix” the formatting (to your liking).
import pandas as pd from datetime import datetime def fixtime(mydate): return datetime.strptime(mydate, '%a %b %d %H:%M:%S +0000 %Y') df = pd.read_csv("mytweets.csv") df["CREATED_AT"] = df.apply(lambda row: fixtime(row["CREATED_AT"]), axis = 1)
The resulting format becomes a Timestamp
data type that looks like this: 2015-03-04 02:14:57