該函式只對dataframe或series型別有效,用於去除重複值。
引數有三個:
#舉個例子
dataframe = pd.read_excel(
"data.xlsx"
)dataframe2 = pd.read_excel(
"data.xlsx"
)dataframe.drop_duplicates(subset=
none
,keep=
'first'
,inplace=
true
)# 意思即為去除所有列完全相同的資料,刪除時只保留第乙個相同的資料,其餘相同資料刪除,且該操作在原表上執行
dataframe2.drop_duplicates(subset=
['列名2'
],keep=
false
,inplace=
false
)# 意思即為去除列名為列名2所在列中的重複資料(並不在意其餘列是否有重複資料),並刪除所有該列的重複資料,該操作不在原表上執行
假設列2的資料為數字,根據列1為空對應的列2的和
dataframe = pd.read_excel(
"data.xlsx"
)print
( dataframe[dataframe.列1.isnull()]
.列2.
sum(
))
關於pandas的一些筆記
print df.loc 1,row labels 取行索引為1,列索引為row labels的資料 8 t1 df.loc 1,2 取第一行和第二行,等價於df.loc 1,2 9 t2 df.loc 1,2 row labels count animalname 取塊10 t3 df.iloc ...
pandas使用的一些技巧
偶然學到了一些技巧,不知道寫在哪兒,就記在這吧,持續更新ing loc是最慢的。盡量用ix代替。pandas 存在 df.iterrows 的generator 來迴圈dataframe 的 row,這樣的效率是最高的。文件丟在這 轉乙個部落格作為參考 我用的時候 for i,row in tqdm...
pandas的一些用法
讀取以 t為分隔符的不帶volume的資料names a b c d e f g df pd.read table filename sep t names names 刪除df中某一行df.drop labels none axis 0,index none columns none level ...