0

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 '
2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.