I am trying to parse and save my IG messages for stat purposes.
I have the following code that works and saves to a csv file, but when i open the file each line is wrapped in " " like so ("2022-06-29,08:50 AM,Joe,Liked a message"), so when i try to import the data into excel, its not split out correctly, thats issue #1
Issue #2 is how the date is formatted, either im not choosing the correct format below or just missing something, but the date that is placed in the file is formatter as the below code shows yyyy-mm-dd i need to have it formatted in mm/dd/yyyy
Issue #3 same thing with the time, in this case i need to include the seconds in the format, currently the below returns 07:05 PM, but need it to return 07:05:00 PM
Can someone suggest what im doing wrong or offer some samples that i can change or implement in my code to clean up the results some more.
I have the following code that works and saves to a csv file, but when i open the file each line is wrapped in " " like so ("2022-06-29,08:50 AM,Joe,Liked a message"), so when i try to import the data into excel, its not split out correctly, thats issue #1
Issue #2 is how the date is formatted, either im not choosing the correct format below or just missing something, but the date that is placed in the file is formatter as the below code shows yyyy-mm-dd i need to have it formatted in mm/dd/yyyy
Issue #3 same thing with the time, in this case i need to include the seconds in the format, currently the below returns 07:05 PM, but need it to return 07:05:00 PM
Can someone suggest what im doing wrong or offer some samples that i can change or implement in my code to clean up the results some more.
import json from datetime import datetime import pandas as pd import os f = open('message_1.json') data = json.load(f) lv = [] for message in data["messages"]: timestamp = datetime.fromtimestamp(message["timestamp_ms"] / 1000) date_val = timestamp.strftime('%Y-%m-%d') time_val = timestamp.strftime("%I:%M %p") if 'content' not in message: st = date_val + "," + time_val + "," + message["sender_name"] + "," + "" lv.append(st) else: st = date_val +"," + time_val + "," + message["sender_name"] + "," + message["content"] lv.append(st) df = pd.DataFrame(lv)