私のCSVには2つの列があります(新しい家の住所とcsvの中でCan
がキャンセルされました)。アドレスが取り消された場合、Can
の下にTrueを書き込む必要がありますが、エンドユーザーがTrueを書き込むのを忘れて、同じAddressが2回表示されることがあります。私はPythonにを教えてください。(削除しないでください)最初に取り消されることなく2回現れるアドレス。重複した住所を表示するパンダ
例:あなたは上記の例から見ることができたよう
Date_Booked Address of New Home Can
01/07/2017 1234 SO Drive True
02/14/2017 4321 Python Court
03/17/2017 1234 SO Drive
03/23/2017 4321 Python Court
、1234 SOドライブがキャンセルされたと真が書かれていた、それは二度書かれた理由をされて、これは私たちが望むものであるが、4321 Pythonの裁判所はそれを取り消されましたCanceledの下ではTrueとは言わないので、CSVに2回表示され、あらゆる種類の問題が発生します。どのような援助がいただければ幸いです
Traceback (most recent call last):
File "pandas\index.pyx", line 154, in pandas.index.IndexEngine.get_loc (pandas\index.c:4279)
File "pandas\src\hashtable_class_helper.pxi", line 404, in pandas.hashtable.Int64HashTable.get_item (pandas\hashtable.c:8543)
TypeError: an integer is required
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
dup_addresses = non_cancelled.groupby('Address of New Home').filter(lambda x: len (x) > 1)
KeyError: 'Address of New Home'
:
import pandas as pd
first = pd.read_csv('Z:PCR.csv')
df = pd.DataFrame(first)
non_cancelled = df['Can'].apply(lambda x: x != 'True')
dup_addresses = non_cancelled.groupby('Address of New Home').filter(lambda x: len (x) > 1)
if not dup_addresses.empty:
raise Exception ('Same address written twice without cancellation')
私は、次のエラーを取得しています。
ありがとう、とにかく「True」でそれらを更新するのではなく、「End User Missed」でそれらを更新できます。 –
npは 'numpy'だと思います。 –
@JakeWagnerはい、申し訳ありません。この場合はどこにいても便利です。構文はより洗練されています。私たちはまだパンダを使うことができましたが、それはもっと醜いです。これを解決するには、さまざまな方法が考えられます。最も挑戦していたことを理解していました。 – piRSquared