English 中文(简体)
使用Np.nan而不进口 n
原标题:Use np.nan without importing numpy

我被用来用NaN替换空洞,并丢弃空数据。

import pandas as pd
import numpy as np

df.replace(  , np.nan).dropna()

然而,我希望我的职能是利用没有服务器的框架。 我需要import numpy, 仅需要使用np.nan, 后者在包裹尺寸上载上我宝贵的250MB限额。

进口<代码>pd.np.nanwork,但有警告说,pandas.np模块已经折旧,并将从今后版本的安达中删除。

是否有任何办法使用<代码>np.nan Without import numpy ?

最佳回答

使用<代码>pd.NA。

From :

从pandas 1.0开始,可提供实验性<代码>pd.NA值(ingleton)作为缺漏数值。 此时此刻,它被用于作为缺失价值指标的无法否认的分类、 b和专用数据类型。 <代码>pd.NA 提供“发送”指标,可按数据类型一致使用(而不是<代码>np.nanp.、Nonepd.NaT

问题回答

也许你可以放弃<条码>日标/代码>:

import math


math.nan
# nan

or even without importing anything:

float( nan )
# nan

这些内容符合NumPy snan:

import numpy as np


np.isnan(math.nan)
# True

np.isnan(float( nan ))
# True

也许Im没有明显的东西,但df.replace( , 无)dropna()应当有效?





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签