Empty Na in dataFrame columns
up vote
0
down vote
favorite
df
Letter city state
0 A NYC NY
1 B Na CT
2 C LA Na
3 D Tampa FL
4 E Na Na
5 F Dallas TX
6 G Denver CL
df['city']=df['city'].str.replace("Na"," ")
df['state']=df['state'].str.replace("Na"," ")
df
Letter city state
0 A NYC NY
1 B CT
2 C LA
3 D Tampa FL
4 E
5 F Dallas TX
6 G Denver CL
df.isnull().any()
Letter False
city False
state False
dtype: bool
How to empty Na to become:
Letter False
city True
state True
python dataframe
add a comment |
up vote
0
down vote
favorite
df
Letter city state
0 A NYC NY
1 B Na CT
2 C LA Na
3 D Tampa FL
4 E Na Na
5 F Dallas TX
6 G Denver CL
df['city']=df['city'].str.replace("Na"," ")
df['state']=df['state'].str.replace("Na"," ")
df
Letter city state
0 A NYC NY
1 B CT
2 C LA
3 D Tampa FL
4 E
5 F Dallas TX
6 G Denver CL
df.isnull().any()
Letter False
city False
state False
dtype: bool
How to empty Na to become:
Letter False
city True
state True
python dataframe
1
Could you format your question and add the data in a way it can be copied and pasted directly into the editor.
– Daniel Mesejo
Nov 18 at 2:03
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
df
Letter city state
0 A NYC NY
1 B Na CT
2 C LA Na
3 D Tampa FL
4 E Na Na
5 F Dallas TX
6 G Denver CL
df['city']=df['city'].str.replace("Na"," ")
df['state']=df['state'].str.replace("Na"," ")
df
Letter city state
0 A NYC NY
1 B CT
2 C LA
3 D Tampa FL
4 E
5 F Dallas TX
6 G Denver CL
df.isnull().any()
Letter False
city False
state False
dtype: bool
How to empty Na to become:
Letter False
city True
state True
python dataframe
df
Letter city state
0 A NYC NY
1 B Na CT
2 C LA Na
3 D Tampa FL
4 E Na Na
5 F Dallas TX
6 G Denver CL
df['city']=df['city'].str.replace("Na"," ")
df['state']=df['state'].str.replace("Na"," ")
df
Letter city state
0 A NYC NY
1 B CT
2 C LA
3 D Tampa FL
4 E
5 F Dallas TX
6 G Denver CL
df.isnull().any()
Letter False
city False
state False
dtype: bool
How to empty Na to become:
Letter False
city True
state True
python dataframe
python dataframe
edited Nov 18 at 2:37
d_kennetz
1,317515
1,317515
asked Nov 18 at 1:57
Ray
162
162
1
Could you format your question and add the data in a way it can be copied and pasted directly into the editor.
– Daniel Mesejo
Nov 18 at 2:03
add a comment |
1
Could you format your question and add the data in a way it can be copied and pasted directly into the editor.
– Daniel Mesejo
Nov 18 at 2:03
1
1
Could you format your question and add the data in a way it can be copied and pasted directly into the editor.
– Daniel Mesejo
Nov 18 at 2:03
Could you format your question and add the data in a way it can be copied and pasted directly into the editor.
– Daniel Mesejo
Nov 18 at 2:03
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
Starting with your original df
, you can just do:
df.eq("Na").any()
Alternately, starting from the second df
, after you replace Na
with empty string, replace the empty strings with NaN
:
import numpy as np
df.replace('', np.nan).isnull().any()
Both produce:
Letter False
city True
state True
dtype: bool
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Starting with your original df
, you can just do:
df.eq("Na").any()
Alternately, starting from the second df
, after you replace Na
with empty string, replace the empty strings with NaN
:
import numpy as np
df.replace('', np.nan).isnull().any()
Both produce:
Letter False
city True
state True
dtype: bool
add a comment |
up vote
2
down vote
Starting with your original df
, you can just do:
df.eq("Na").any()
Alternately, starting from the second df
, after you replace Na
with empty string, replace the empty strings with NaN
:
import numpy as np
df.replace('', np.nan).isnull().any()
Both produce:
Letter False
city True
state True
dtype: bool
add a comment |
up vote
2
down vote
up vote
2
down vote
Starting with your original df
, you can just do:
df.eq("Na").any()
Alternately, starting from the second df
, after you replace Na
with empty string, replace the empty strings with NaN
:
import numpy as np
df.replace('', np.nan).isnull().any()
Both produce:
Letter False
city True
state True
dtype: bool
Starting with your original df
, you can just do:
df.eq("Na").any()
Alternately, starting from the second df
, after you replace Na
with empty string, replace the empty strings with NaN
:
import numpy as np
df.replace('', np.nan).isnull().any()
Both produce:
Letter False
city True
state True
dtype: bool
edited Nov 18 at 4:46
answered Nov 18 at 2:42
andrew_reece
10.2k1927
10.2k1927
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53357240%2fempty-na-in-dataframe-columns%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Could you format your question and add the data in a way it can be copied and pasted directly into the editor.
– Daniel Mesejo
Nov 18 at 2:03