I have created a function in python that queries data directly from SQL database using the pyodbc library. The problem is that pd.read_csv in the function generates a dataframe where columns expected to be integers are floats and columns with strings have extra spaces after the column values. How do i resolve this problem?
Here is a sample of the code
import pyodbc
import pandas as pd
def query(sql_query):
conn = pyodbc(connection details)
cursor = conn.cursor()
df = pd.read_csv(sql_query, conn)
return df
Expected
| Column A | Column B |
|---|---|
| 1 | value1 |
| 2 | value2 |
Output
| Column A | Column B |
|---|---|
| 1.0 | 'value1 ' |
| 2.0 | 'value2 ' |