1 回答

TA貢獻(xiàn)1830條經(jīng)驗 獲得超3個贊
您可以使用多種 Pandas 函數(shù)?;旧?,您可以用來按內(nèi)容過濾數(shù)據(jù)框的語法是:
df = df[(condition1) & (condition2) & ...] # filter the df and assign to the same df
專門針對您的情況,您可以替換condition為以下函數(shù)(表達(dá)式):
df[some_column] == some_value
df[some_column].isin(some_list_of_values) # This check whether the value of the column is one of the values in the list
df[some_column].str.contains() # You can use it the same as str.contains()
df[some_column].str.isdigit() # Same usage as str.isdigit(), check whether string is all digits, need to make sure column type is string in advance
df[some_column].str.len() == 4 # Filter string with length of 4
最后,如果要重置索引,可以使用df = df.reset_index(drop=True)將輸出 df 索引重置為 0,1,2,...
編輯:要檢查您可以使用的 NaN、NaT、None 值
df[some_column].isnull()
對于多列,您可以使用
df[[col1, col2]].isin(valuelist).all(axis=1)
添加回答
舉報