I’m working with pyodbc to fetch data from a SQL Server database and convert it to a pandas dataframe. However, I’m running into a strange issue where multiple columns from my query get squashed into just one column.
The error message I keep seeing is:
ValueError: Shape of passed values is (18,1) indices imply (18,2)
This is weird because the same approach worked fine when I used it with Teradata connections before. It seems like the query recognizes that there should be two columns but only returns one row of data.
Here’s my current code:
connection = pyodbc.connect(connection_string)
cur = connection.cursor()
result = cur.execute("Select [Name], [Surname] from [Users] where [UserID] > 100")
users_df = pd.DataFrame(result, columns = [col[0] for col in cur.description])
When I take out the columns parameter, the dataframe shows something like:
0
0 [Mike, Johnson]
Has anyone encountered this before? What could be causing the columns to merge together like this?