私は値のpythonパンダでどのようにpandas、pythonで特定のオブジェクトを持つ行を削除しますか?
はい
はい
どのように私は希望のこれらの種類が含まれている私のデータの列を持っています文字列を含む行全体を識別し、行全体を削除または削除しますか?
おかげ
私は値のpythonパンダでどのようにpandas、pythonで特定のオブジェクトを持つ行を削除しますか?
はい
はい
どのように私は希望のこれらの種類が含まれている私のデータの列を持っています文字列を含む行全体を識別し、行全体を削除または削除しますか?
おかげ
IIUC:
df = df[~pd.to_numeric(df['col'], errors='coerce').isna()]
または
df = df[pd.to_numeric(df['col'], errors='coerce').notna()]
はここでこれを解決する方法です。 DataFrameを構築するためのコードを含めました。 文字列の値を見つけてドロップします。 df.dropは、inplace = Trueを指定しない限り、元のdfの変更されたコピー を返します。必要に応じて、df df = df.drop...
の元の名前を割り当てるか、inplace引数を使用します。
import pandas as pd
import numpy as np
# build the df
df = pd.DataFrame({'col_name' : [2, 2, 'yes', 2, 'yes']})
print(df)
col_name
0 2
1 2
2 yes
3 2
4 yes
# ask what are the types in column
df.col_name.apply(type)
0 <class 'int'>
1 <class 'int'>
2 <class 'str'>
3 <class 'int'>
4 <class 'str'>
Name: col_name, dtype: object
# you can see that the strings are in row 2 and 4
# and drop them like this
df.drop([2, 4], axis='rows')
col_name
0 2
1 2
3 2
df.drop(df ['col'] == 2).index) –
完了した行のみを返すようですか? – KRidg
値が見つからなかったすべての行が移入されました。感謝!! – KRidg