{"record":{"id":"cc4990e08be72410","repo":"dotnet/machinelearning","slug":"column-0-does-not-exist","errorCode":null,"errorMessage":"Column '{0}' does not exist","messagePattern":"Column '(.+?)' does not exist","errorType":"validation","errorClass":"System.ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.Data.Analysis/DataFrame.cs","lineNumber":371,"sourceCode":"                shuffleLowerLimit++;\n            }\n            ArraySegment<int> segment = new ArraySegment<int>(shuffleArray, 0, shuffleLowerLimit);\n\n            PrimitiveDataFrameColumn<int> indices = new PrimitiveDataFrameColumn<int>(\"indices\", segment);\n\n            return Clone(indices);\n        }\n\n        /// <summary>\n        /// Groups the rows of the <see cref=\"DataFrame\"/> by unique values in the <paramref name=\"columnName\"/> column.\n        /// </summary>\n        /// <param name=\"columnName\">The column used to group unique values</param>\n        /// <returns>A GroupBy object that stores the group information.</returns>\n        public GroupBy GroupBy(string columnName)\n        {\n            int columnIndex = _columnCollection.IndexOf(columnName);\n            if (columnIndex == -1)\n                throw new ArgumentException(String.Format(Strings.InvalidColumnName, columnName), nameof(columnName));\n\n            DataFrameColumn column = _columnCollection[columnIndex];\n            return column.GroupBy(columnIndex, this);\n        }\n\n        /// <summary>\n        /// Groups the rows of the <see cref=\"DataFrame\"/> by unique values in the <paramref name=\"columnName\"/> column.\n        /// </summary>\n        /// <typeparam name=\"TKey\">Type of column used for grouping</typeparam>\n        /// <param name=\"columnName\">The column used to group unique values</param>\n        /// <returns>A GroupBy object that stores the group information.</returns>\n        public GroupBy<TKey> GroupBy<TKey>(string columnName)\n        {\n            GroupBy<TKey> group = GroupBy(columnName) as GroupBy<TKey>;\n\n            if (group == null)\n            {\n                DataFrameColumn column = this[columnName];","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.Data.Analysis/DataFrame.cs#L353-L389","documentation":"DataFrame.GroupBy(columnName) looks the column up with IndexOf and throws ArgumentException (Strings.InvalidColumnName, 'Column \\'{0}\\' does not exist') when the name is not found. The library needs the column's index to build the GroupBy object, so an unknown name is rejected. This error also surfaces from GroupBy<T>, Count, First, Head, Tail, Max etc., which all call GroupBy internally.","triggerScenarios":"df.GroupBy(\"Sales\") where no column is literally named 'Sales' — typos, different casing, names with whitespace, or columns that were never loaded (CSV header mismatch) or renamed/dropped earlier in the pipeline.","commonSituations":"Case-sensitive mismatch ('sales' vs 'Sales'); CSV headers with BOM or trailing spaces; a column added conditionally; renaming a column in one pipeline stage but not downstream consumers.","solutions":["Verify the exact name against df.Columns — print or assert the column list before grouping.","Match casing and trim whitespace from the column name string (headers may carry a BOM or spaces).","Guard with df.Columns.Contains(columnName) before calling GroupBy and give a clear error if absent.","Catch ArgumentException around GroupBy to report the missing column in user-facing messages."],"exampleFix":"// before\nvar g = df.GroupBy(\"Categry\");\n// after\nif (!df.Columns.Contains(\"Category\"))\n    throw new InvalidOperationException($\"Column missing. Have: {string.Join(',', df.Columns.Select(c => c.Name))}\");\nvar g = df.GroupBy(\"Category\");","handlingStrategy":"validation","validationCode":"if (!df.Columns.Contains(columnName))\n    throw new InvalidOperationException($\"Column '{columnName}' missing. Available: {string.Join(',', df.Columns.Select(c => c.Name))}\");\nvar g = df.GroupBy(columnName);","typeGuard":"bool HasColumn(DataFrame df, string name) => df.Columns.Contains(name);","tryCatchPattern":"try { g = df.GroupBy(columnName); }\ncatch (ArgumentException ex) { logger.LogError(ex, \"GroupBy column '{0}' not found\", columnName); throw; }","preventionTips":["Trim/BOM-strip CSV headers on load so names match exactly","Centralize column names as constants instead of string literals","Log df.Columns names when a schema mismatch is suspected"],"tags":["column-not-found","groupby","keyerror","dataframe"],"backgroundTag":"entity-not-found","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}