【发布时间】:2018-07-19 11:06:13
【问题描述】:
我想用 pandas 将我的 excel 表插入数据库(Microsoft SQL Server)。我首先使用 ExcelFile 而不是 read_excel 并使用了解析,但解析不适用于 read_excel。 我更喜欢使用 read_excel,因为文件是根据需要形成的
这是我的代码:
if __name__ == '__main__':
cursor = get_sql_conn().cursor()
local_files = 'C:\\Users\\dersimw\\Source\Repos\\nordpoolAnalyse\\data\\2011-3.xlsx'
cols = [1,7,13,19,25, 31, 37, 43, 49, 55, 61, 67, 73, 79, 85, 91, 97, 103, 109, 115, 121, 127, 133, 139]
excelFile = pd.read_excel(local_files, sheet_name= "01", header = None, usecols= cols)
print(excelFile.head(6))
这是我要插入数据库的文件:
--------------------------------------------------------------------------
| 0 1 2 3 ... 20 21 22 23 |
---------------------------------------------------------------------------
| 0 0 1 2 3 ... 20 21 22 23 |
| 1 112 112 112 112 ... 227.5 227 52 52 |
| 2 1573.2 1575.2 1596.1 1603.1 ... 1896.8 1833.8 1728.3 1649.3 |
| 3 NaN NaN NaN NaN ... NaN NaN NaN NaN |
| 4 NaN NaN NaN NaN ... NaN NaN NaN NaN |
| 5 2652.3 2505.9 2662.6 2712.7 ... 1613.2 2932 2962 2897 |
-----------------------------------------------------------------------------
感谢所有回答
【问题讨论】:
标签: python sql-server excel pandas dataframe