python - Why does pandas.Dataframe.drop() returns None? -
here in code read data csv:
data = pandas.read_csv('dataset/job_functions.csv', names=["job","category"] ,skiprows=1).dropna().reindex() num_jobs = data["job"].size then want drop rows 'category' label not equal i:
data = data.drop(data[data.category!=i].index,inplace = true) print(data.head()) even dropping list of index returns none:
data = data.drop(data.index[[1,2,3]],inplace = true) error message:
traceback (most recent call last): file "sample.py", line 162, in delete_common_words(27) file "sample.py", line 92, in delete_common_words print(data.head()) attributeerror: 'nonetype' object has no attribute 'head'
here data until use drop():
job category 0 офис менеджер реализация гербицидовоформлени... 2 1 менеджер отдел продажа работа с существующий... 27 2 ведущий бухгалтер работа с вендер и поставщи... 1 3 менеджер по продажа и продвижение продукт ус... 27 4 юрист проведение юридический экспертиза прое... 13
it looks need boolean indexing:
import pandas pd data = pd.dataframe({'category':['a','b', 'c']}) print (data) category 0 1 b 2 c = 'a' print (data[data.category != i]) category 1 b 2 c print (data[~data.category.isin(['b','c'])]) category 0 and edchum explains, if use inplace=true return none, can use:
#omit inplace=true data = data.drop(data[data.category!=i].index) or:
#remove assigning data.drop(data[data.category!=i].index,inplace = true)
Comments
Post a Comment