[英]new to coding and python. trying to force type (int) for a float answer
[英]I am trying to delete the specific rows(MB, DT) of a cloumn(“TYPE”) from a dataframe in python. Can anyone provide the answer
列(“TYPE)”包含“IL”、“FC”、“DT”、“MB”。
test_data = test_data.drop(test_data[test_data.Type,='IL', 'FC'])
假設您的 dataframe 只有索引列和類型列
data = {'TYPE':['IL', 'FC', 'DT', 'MB']}
df = pd.DataFrame(data)
df
TYPE
0 IL
1 FC
2 DT
3 MB
如果要刪除 DT、MB 行 (2,3),則可以選擇以下之一(不是唯一的):
df1 = df[:2]
df1
TYPE
0 IL
1 FC
df.drop(df.index[[2,3]], inplace = True)
df2 = df[(df['TYPE']!='DT') & (df['TYPE']!='MB')]
df2
TYPE
0 IL
1 FC
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.