pyodbc.connect() works, but not sqlalchemy.create_engine().connect()

A Pass through exact Pyodbc string works for me: import pandas as pd from sqlalchemy import create_engine from sqlalchemy.engine import URL connection_string = ( r”Driver=ODBC Driver 17 for SQL Server;” r”Server=(local)\SQLEXPRESS;” r”Database=myDb;” r”Trusted_Connection=yes;” ) connection_url = URL.create( “mssql+pyodbc”, query={“odbc_connect”: connection_string} ) engine = create_engine(connection_url) df = pd.DataFrame([(1, “foo”)], columns=[“id”, “txt”]) pd.to_sql(“test_table”, engine, if_exists=”replace”, index=False)

Difference between df[x], df[[x]], df[‘x’] , df[[‘x’]] and df.x

df[x] — index a column using variable x. Returns pd.Series df[[x]] — index/slice a single-column DataFrame using variable x. Returns pd.DataFrame df[‘x’] — index a column named ‘x’. Returns pd.Series df[[‘x’]] — index/slice a single-column DataFrame having only one column named ‘x’. Returns pd.DataFrame df.x — dot accessor notation, equivalent to df[‘x’] (there are, however, … Read more

how to understand closed and label arguments in pandas resample method?

Short answer: If you use closed=’left’ and loffset=”2T” then you’ll get what you expected: series.resample(‘3T’, label=”left”, closed=’left’, loffset=”2T”).sum() 2000-01-01 00:02:00 3 2000-01-01 00:05:00 12 2000-01-01 00:08:00 21 Long answer: (or why the results you got were correct, given the arguments you used) This may not be clear from the documentation, but open and closed in … Read more

Remove time portion of DateTime index in pandas

With the date attribute: df.index = df.index.date Example: >>> df = pd.DataFrame([1, 2, 3, 4], index=pd.date_range(‘2018′, periods=4, freq=’H’)) >>> df.index = df.index.date >>> df 0 2018-01-01 1 2018-01-01 2 2018-01-01 3 2018-01-01 4 Note: that this will get you object dtype in Pandas. All attributes are here. It’s technically an array of native Python datetime.date … Read more

Pandas Secondary Axis

IIUC: ax = df.plot(‘Date’,’A’) ax1 = ax.twinx() df.plot(‘Date’,’B’,ax=ax1, color=”r”) Output: Or you can use secondary_y in Pandas plot: ax = df.plot(‘Date’,’A’) df.plot(‘Date’,’B’,secondary_y=True, ax=ax) Output: