python导入数据并重命名_使用函数导入CSV文件,并将数据帧重命名为python 3.6

我有2/2个以上的csv文件在文件夹中,我想导入这些文件到不同的数据帧,并想根据文件名重命名数据帧。在import os

import pandas as pd

redShiftKeyFolderPath = r'D:\Sunil_Work\temp8\Prod_IMFIFSS2017' # contains 2 csv files i.e Prod_IMFIFSS2017_Indicator.csv & Prod_IMFIFSS2017_Location.csv

def importRedshiftKeys(redShiftKeyFolderPath):

for file in os.listdir(redShiftKeyFolderPath):

if file.endswith('.csv'):

redShiftKey = pd.read_csv(os.path.join(redShiftKeyFolderPath, file), dtype = object) # importing

i = file.rfind('_'); file = file[i:]; rDfName = 'redShiftKey_' + file.replace('_', '').replace('.csv', '') # taking last part of the file name after _ & excluding .csv

print('Need to rename dataframe as: ', rDfName)

# Here i want to rename dataframe: "redShiftKey" with new name stored in "rDfName"

return

importRedshiftKeys(redShiftKeyFolderPath)

我希望有2个数据帧,即redShiftKey_指示器和redShiftKey_位置

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值