So, I have this code using pandas.melt(): for idx in range(len(data_rows[0])): if idx == 0: continue data_fields = [row[idx] for row in data_rows] melted_dfs.append(pd.melt(df, id_vars=key_fields, value_vars=data_fields, var_name='variable' + str(idx), value_name=column_names[idx][0])) There is one column common in id_vars and value_vars. id_vars=['first_name', 'last_name'] value_vars=['math_score', 'chemistry_score', 'last_name'] The interesting thing is that when I run this piece of code with python 3.9 and pandas 1.5.3, it works fine. However, with python 3.7 and pandas 1.1.5 it's giving me this error: ValueError: arrays must all be same length There many be any number of common columns in id_vars and value_vars. How can I make it run on python 3.7? (Please note that I cannot change the Python 3.7 configuration.) Continue reading...