第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

驗證熊貓數(shù)據(jù)框列

驗證熊貓數(shù)據(jù)框列

qq_笑_17 2021-08-17 15:46:38
我有一個列如下的數(shù)據(jù)框 -u'wellthie_issuer_identifier', u'issuer_name', u'service_area_identifier', u'hios_plan_identifier', u'plan_year', u'type'我需要驗證每一列中的值,最后有一個有效的數(shù)據(jù)框。例如,我需要檢查plan_year列是否滿足以下驗證presence: true, numericality: true, length: { is: 4 }hios_plan_identifier 列滿足以下正則表達(dá)式。          format: /\A(\d{5}[A-Z]{2}[a-zA-Z0-9]{3,7}-TMP|\d{5}[A-Z]{2}\d{3,7}(\-?\d{2})*)\z/,           presence: true, length: { minimum: 10 },type 列包含,in: ['MetalPlan', 'MedicarePlan', 'BasicHealthPlan', 'DualPlan', 'MedicaidPlan', 'ChipPlan']有很多列需要驗證。我試圖給出一個示例數(shù)據(jù)。我可以用 s 檢查正則表達(dá)式tr.contains('\A(\d{5}[A-Z]{2}[a-zA-Z0-9]{3,7}-TMP|\d{5}[A-Z]{2}\d{3,7}(\-?\d{2})*)\Z', regex=True)同樣,我也可以單獨檢查其他驗證。我對如何將所有驗證放在一起感到困惑。我應(yīng)該把所有的都放在一個有條件的if循環(huán)中and嗎?有沒有一種簡單的方法來驗證數(shù)據(jù)框列?在這里需要幫助
查看完整描述

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)


查看完整回答
反對 回復(fù) 2021-08-17
  • 1 回答
  • 0 關(guān)注
  • 154 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號