Output column names - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Output column names (/thread-11146.html) |
Output column names - Scott - Jun-25-2018 Hi Everyone, I am running a model and then I output the most import features with this code. feature_importances = grid_search.best_estimator_.feature_importances_ feature_importancesIt gives me an array like this: array([0.05771354, 0.05546155, 0.00769528, 0.03085979, 0.01987578, 0.05596404, 0.08724213, 0.04514583, 0.03068226, 0.03416644, 0.033704 , 0.03123091, 0.04680151, 0.04481024, 0.04322517, 0.04328215, 0.04302698, 0.04359057, 0.04307562, 0.04042718, 0.03971901, 0.03909929, 0.04083307, 0.04236768]) Is there anyway I can get python to print the column names as well so i know what variable has what weighting? Thanks Scott RE: Output column names - gontajones - Jun-25-2018 Where did this array come from? The columns are the params (dictionary's keys) of the dataframe. RE: Output column names - volcano63 - Jun-25-2018 (Jun-25-2018, 09:06 AM)Scott Wrote: Is there anyway I can get python to print the column names as well so i know what variable has what weighting?The API returned you a numpy.array - numpy does not have a notion of a named column. Columns are properties of pandas.DataFrame - which is a wrapper over numpy arrays.Whether your API returns values per columns or per rows, you have to combine your data accordingly |