我正在嘗試選擇表中的行并使用 PETL 使用原始表中的信息創建一個新表。我現在的代碼是:import petl as etltable_all = ( etl.fromcsv("practice_locations.csv") .convert('Practice_Name', 'upper') .convert('Suburb', str) .convert('State', str) .convert('Postcode', int) .convert('Lat', str) .convert('Long', str))def selection(post_code): table_selected = etl.select(table_all, "{Postcode} == 'post_code'") print(post_code) etl.tojson(table_selected, 'location.json', sort_keys=True)但是我似乎無法table_selected按原樣使用選擇功能進行填充。etl.select如果我替換post_code為看起來像,呼叫將起作用table_selected = etl.select(table_all, "{Postcode} == 4510")輸出正確的表,如下所示: +--------------------------------+--------------+-------+----------+--------------+--------------+ | Practice_Name | Suburb | State | Postcode | Lat | Long | +================================+==============+=======+==========+==============+==============+ | 'CABOOLTURE COMBINED PRACTICE' | 'Caboolture' | 'QLD' | 4510 | '-27.085007' | '152.951707' | +--------------------------------+--------------+-------+----------+--------------+--------------+我確定我只是想以post_code錯誤的方式調用,但已經嘗試了 PETL 文檔中的所有內容,但似乎無法弄清楚。任何幫助深表感謝。
添加回答
舉報
0/150
提交
取消