Spaces:
Sleeping
Sleeping
File size: 1,063 Bytes
72b9525 | 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 | 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) |