Pandas DF列到SQLite表

2024-04-18 03:52:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我在sqlite中创建了一个数据库,它是从pandas的字典中创建的,数据帧是从csv的文件中创建的。当我将数据库导入sqlite时,每个表名都以“.csv”结尾,我如何删除它?在

代码如下:

import os
import glob
import pandas as pd

files = glob.glob(os.path.join("staging" + "/*.csv"))

print(files)

# Create an empty dictionary to hold the dataframes from csvs
dict_ = {}

# Write the files into the dictionary
for file in files:
    fname = os.path.basename(file)
    dict_[fname] = pd.read_csv(file, header = 0, dtype = str, encoding = 'cp1252').fillna('')

对于sqlite数据库:

^{pr2}$

Tags: csvthepathimport数据库pandassqlitedictionary