-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoutput.py
More file actions
36 lines (30 loc) · 1.44 KB
/
output.py
File metadata and controls
36 lines (30 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import pandas as pd
def save_to_csv(data, filename):
"""Converts a list of dictionaries into a DataFrame and saves it to a CSV file."""
pd.DataFrame(data).to_csv(f'Output/{filename}.csv', index=False)
# def get_memory_data(memory):
# """Extracts relevant data from memory for CSV conversion."""
# return [{
# 'ID': ids,
# 'Author': metadata['Author'],
# 'Iteration': metadata['Iteration'],
# 'Sentiment Score': metadata['Sentiment Score'],
# 'Virality Score': metadata['Virality Score'],
# 'Content_ID': metadata.get('Content_ID', 'N/A'),
# 'Is_Retweet': metadata.get('Is_Retweet', False),
# 'Document': document
# } for ids, metadata, document in zip(memory['ids'], memory['metadatas'], memory['documents'])]
def get_memory_data(memory):
"""Extracts relevant data from memory for CSV conversion."""
return [{
'ID': ids,
'Author': metadata['Author'],
'Iteration': metadata['Iteration'],
'Sentiment Score': metadata['Sentiment Score'],
'Virality Score': metadata['Virality Score'],
'Content_ID': ids,
'Is_Retweet': metadata.get('Is_Retweet', False),
'Original_Content_ID': metadata.get('Original_Content_ID'),
'Direct_Interaction_ID': metadata.get('Direct_Interaction_ID'),
'Document': document
} for ids, metadata, document in zip(memory['ids'], memory['metadatas'], memory['documents'])]