我想用pandas将excel表插入数据库(microsoftsqlserver)。我使用了第一个ExcelFile,而不是read\u excel和parse,但是parse不能与read\u excel一起工作。 我更喜欢使用read\u 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 |
-----------------------------------------------------------------------------
谢谢你的回答
如果您拥有Excel文件中的所有数据,只需将其粘贴到数据库中即可。 你可以用
以下是链接: to_sql
我希望这对你有帮助。你知道吗
相关问题 更多 >
编程相关推荐