你可以在mac OS应用程序中使用Python脚本吗?

时间:2017-01-27 02:34:15

标签: python swift xcode macos pandas

我正在尝试运行我在Python中编写的一个简短的排序程序,但我想在Swift macOS应用程序中调用该程序。该程序旨在获取一个大型csv文件,并根据一些硬编码标准对其进行排序。我希望能够在不使用命令行的情况下完成所有操作并拥有一个非常简单的mac OS应用程序UI。

这是该计划的快照:

def add_data(qualifiers_master,data):

    # Set the right parameters
    base_counter = 2
    index_counter = 7
    iterations = len(qualifiers_master)

    # Create a masterList for the data to be contained
    master_list = []

    # Grab dictionary
    for qualifier in qualifiers_master:
        for row_num in range(4,len(data)):

            # Counter for iterations of parameters in the report
            if iterations > 0:

                #
                # Create the clean data in strings
                #
                # This looks bad but its just filtering out the punctuation
                base_count_number = ''.join([i for i in data[row_num][base_counter] if i.isdigit() == True])
                try:
                    base_count = int(base_count_number)
                except ValueError:
                    pass
                market_index_number = ''.join([i for i in data[row_num][index_counter] if i.isdigit() == True])
                try:
                    market_index = int(market_index_number)
                except ValueError:
                    pass
                # Cleaning ZipCode
                zip_code = str(data[row_num][0])

            # Filter for lower than 120 BaseCount

            try:
                if int(market_index) >= 120:

                    # Begin creating a dictionary to add to the master_list container
                    working_dict={}

                    working_dict['name'] = qualifier
                    working_dict['baseCount'] = base_count
                    working_dict['marketPotentialIndex'] = market_index
                    working_dict['zipCode'] = zip_code

                    master_list.append(working_dict)

                    working_dict={}
            except ValueError:
                pass

        # Maintaining the indexes for the data
        base_counter += 6
        index_counter += 6
        iterations -= 1

    return master_list



def main():

    import pandas as pd

    file_name = input('What is the name of the file?\n') 
    print("Thanks! I'm gonna sort it now for you...")`

0 个答案:

没有答案