Python3:输出文件名应包含csv文件上条件的修改值

时间:2018-08-15 18:43:20

标签: python-3.x file output filenames

我有一个curr_state.csv文件,其中包含以下内容:

curr_state
LanguageHint
SpecialAnnouncementInitial
EscalateFlush
EscalateExecute

我目前正在以以下方式读取此文件: state = [pd.read_csv(str(curr_state))]

我还有一个28列的主要csv文件。列之一是curr_state。请注意,curr_state.csv文件包含具有唯一值的同一curr_state列,尽管已对其进行了修改,没有点和驼峰。 (即主文件上的curr_state读为language.hint,而curr_state.csv为LanguangeHint

curr_state
language.hint
special.announcement.initial
curr_state
escalate.flush
curr_state
escalate.execute

我目前有以下代码,按curr_state进行分组

state = {f'abc_{Client}_{Channel}_{state}_{filedate}': df_state \
     for state, df_state in df.groupby('curr_state')}

这是创建输出csv文件的方法。

for k, v in d.items():
    v.to_csv(f'{k}.csv', sep=',', encoding='utf-8', index=False)

由于我已经将curr_state列表置于状态,所以我不确定为什么上面的代码没有更改输出文件

我希望输出文件名是

abc_ClientName_Phone_LanguageHint_SpecificDate.csv

但是现在我得到了:

abc_ClientName_Phone_language.hint_SpecificDate.csv

0 个答案:

没有答案