python - ValueError: Length of values does not match length of index . . . Both errors out: ValueError: Length of values does not match length of index Because the data frame has four rows but the list and array has only two elements Work around Solution (use with caution): convert the list array to a pandas Series, and then when you do assignment, missing index in the Series will be filled with NaN:
Python index of item in list without error? - Stack Overflow Exceptions in Python are not just for errors, they are for exceptional circumstances - hence the name If list index () had returned some special value, it would need to be one which could not have been returned had list index () found the item could not subsequently be misinterpreted by naïve code
python - How to set in pandas the first column and row as index . . . When I read in a CSV, I can say pd read_csv ('my csv', index_col=3) and it sets the third column as index How can I do the same if I have a pandas dataframe in memory? And how can I say to use the first row also as an index? The first column and row are strings, rest of the matrix is integer