Receiving this error '[nan nan nan ... nan nan nan] not found in axis'
When trying to drop columns from a dataframe if the value is zero
train_df.head()
external_company_id company_name email_domain mx_record ...
NaN Expresstext expresstext.net unknown expresstext.net ... 0.0 0.0 0.0 0.0
NaN Jobox jobox.ai unknown www.jobox.ai ... 17.0 -31.0 9.0 30.0
NaN Relola relola.com unknown home.relola.com ... 5.0 -25.0 5.0
train_df.drop(train_df[train_df['total_funding'] == float(0)].index, inplace = True, axis=0)
'[nan nan nan ... nan nan nan] not found in axis'
What would be causing this error?
I learned that pandas automatically uses the first column as the index for read_csv. Because my first column was empty every index somehow ended up being NaN as seen in the question above.
I ran these two lines of code to create a new index and fill it.
train_df.index.name = 'id'
train_df.index = [x for x in range(1, len(train_df.values)+1)]
Then the former error disapeared
Instead of :
train_df.drop(...)
try:
train_df = train_df[train_df[train_df['total_funding'] != float(0)]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.