Buildingan analysis DataFrame from raw experiment logs often trips teams up on a few recurring pain points. First, inconsistent field names across runs lead to missing columns or unexpected NaNs; a defensive mapping step that supplies defaults (e.g., language=”unknown”) prevents crashes downstream. Second, raw trajectories vary in length and token count, making it hard to compare runs; normalizing each trajectory and counting tokens right after extraction gives a comparable metric that can be used for filtering or weighting later. Third, patch information is frequently buried in nested structures; extracting file counts, added/deleted lines, and churn in a single helper function keeps the main loop clean and reduces bugs from repetitive code. Fourth, role‑based message counts are useful for diagnosing agent behavior but are easy to mis‑calculate if the trajectory contains unexpected role tags; using a dedicated role_counts function that returns zeros for absent roles guarantees stable n_system, n_user, n_assistant, and n_tool fields. Fifth, metadata such as category or number of modified files may be absent; pulling these with .get and supplying sensible fallbacks (e.g., 0 for numeric fields) avoids KeyError exceptions and ensures the DataFrame has a uniform shape. Finally, after assembling the raw records, casting the resolved flag to a boolean is_resolved column and creating a known_label mask simplifies downstream analysis and model training. By wrapping each extraction step in small, testable functions and applying default values early, teams can turn messy logs into a reliable analysis table ready for exploration, visualization, or model feeding.
#AI #Product #DataScience #MachineLearning #Python #Analytics