Spaces:
Sleeping

scripti_sandbox / analytics_v01.py
kaurdotai's picture
analytics_v01 added to see data in a readable and reusable way
72b9525
Raw History Blame Contribute Delete
1.06 kB
import pandas as pd
import pprint
import ast
import json
import argparse
# ... existing imports ...
# Specify the path to your CSV file
file_path = 'data/logged_data_hub_v01.csv'
def process_data(idx):
# Read the CSV file into a DataFrame
df = pd.read_csv(file_path)
# Display the DataFrame
json_story = (df.iloc[idx, 1]) # iloc[:, 1] selects all rows of the second column
str_feedback = (df.iloc[idx, 2])
# Convert the string to a Python object
data_list = ast.literal_eval(json_story)
filtered_data = [{"role": item["role"], "content": item["content"]} for item in data_list]
# Print the data in pretty JSON format
print(json.dumps(filtered_data, indent=4))
print(str_feedback)
if __name__ == "__main__":
# Set up command line argument parsing
parser = argparse.ArgumentParser(description='Process data from CSV file.')
parser.add_argument('idx', type=int, help='Index of the row to process')
args = parser.parse_args()
# Call the function with the provided index
process_data(args.idx)