Setting Column Names In A Pandas Dataframe (python)
When setting a column name for a pandas dataframe, why does the following work: df_coeff = pd.DataFrame(data = lm.coef_, index = X.columns, columns = ['Coefficient']) While this d
Solution 1:
The DataFrame
constructor expects an "Index or array-like" as the column
argument.
['Coefficient']
is a Python list with a single entry, the string'Coefficient'
.'Coefficient'
is not a list, but just a string.
DataFrame
accepts a Python list, but not a string, as an array-like.
Post a Comment for "Setting Column Names In A Pandas Dataframe (python)"