没有创建输出文件

时间:2019-06-19 15:30:45

标签: python

非常简单,此代码应在指定的输出目录中输出摘要文件,而不是摘要文件。我不知道为什么

我尝试编辑配置以及更改目录。

import os
import pandas as pd


def summarise(indir, outfile):
os.chdir(indir)
filelist = ""
dflist = []
colnames = ["DSP Code", "Report Date", "Initial Date", "End Date", "Transaction Type", "Sale Type",
            "Distribution Channel", "Products Origin ID", "Product ID", "Artist", "Title", "Units Sold",
            "Retail Price", "Dealer Price", "Additional Revenue", "Warner Share", "Entity to be billed",
            "E retailer name", "E retailer Country", "End Consumer Country", "Price Code", "Currency Code"]
for filename in filelist:
    print(filename)
    df = pd.read_csv('SYB_M_20171001_20171031.txt', header=None, encoding='utf-8', sep='\t',
                     names=colnames, skiprows=1, usecols=['Units Sold', 'Dealer Price', 'End Consumer Country',
                                                          'Currency Code'])
    # Multiplying units by dealer price will give you sum of file
    df['Sum of Revenue'] = df['Units Sold'] * df['Dealer Price']
    # Get those first two columns
    d = {'Sum of Revenue': 'Total Revenue', 'Units Sold': 'Total Units'}
    for col, newcol in d.items():
        df.loc[df.index[0], newcol] = df[col].sum()
    # Add the rest for every country:
    s = df.groupby('End Consumer Country')['Units Sold'].sum().to_frame().T.add_suffix(' Total')
    s.index = [df.index[0]]

    df = pd.concat([df, s], 1, sort=False)
    df.to_csv(outfile + r"\output.csv", index=None)

    dflist.append(filename)


summarise(r"O:\James Upson\Sound Track Your Brand Testing\SYB Test",
      r"O:\James Upson\Sound Track Your Brand Testing\SYB Test Formatted")

我希望有一个名为'output.csv'的输出文件

1 个答案:

答案 0 :(得分:1)

嗯,好的,我看到filelist = "",然后看到for filename in filelist: 您试图遍历一个空列表