{"id":259,"hash":"5d5f5be85e674aa199acce512f56663a4b1d0a4c5d19822d5bcfcf283e01fe03","pattern":"Constructing DataFrame from values in variables yields &quot;ValueError: If using all scalar values, you must pass an index&quot;","full_message":"I have two variables as follows.\n\na = 2\nb = 3\n\nI want to construct a DataFrame from this:\n\ndf2 = pd.DataFrame({'A':a, 'B':b})\n\nThis generates an error:\n\nValueError: If using all scalar values, you must pass an index\n\nI tried this also:\n\ndf2 = (pd.DataFrame({'a':a, 'b':b})).reset_index()\n\nThis gives the same error message. How do I do what I want?","ecosystem":"pypi","package_name":"pandas","package_version":null,"solution":"The error message says that if you're passing scalar values, you have to pass an index.  So you can either not use scalar values for the columns -- e.g. use a list:\n\n>>> df = pd.DataFrame({'A': [a], 'B': [b]})\n>>> df\n   A  B\n0  2  3\n\nor use scalar values and pass an index:\n\n>>> df = pd.DataFrame({'A': a, 'B': b}, index=[0, 3])\n>>> df\n   A  B\n0  2  3\n3  2  3","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/17839973/constructing-dataframe-from-values-in-variables-yields-valueerror-if-using-all","votes":869,"created_at":"2026-04-19T04:41:41.013486+00:00","updated_at":"2026-04-19T04:51:53.056074+00:00"}