0

Make a list containing two elements : 'None' and None.

x = ['None',None]
x
['None', None]
print(x)
['None', None]

It is obvious that the first is a string whose value is 'None', the second is a NoneType None in python.

Create a dataframe which contain the two element also:

df = pd.DataFrame({"content": ['None', None]})
type(df.iloc[0,0] )
<class 'str'>
type(df.iloc[1,0])
<class 'NoneType'>
df
  content
0    None
1    None
print(df)
  content
0    None
1    None

Maybe python community should make a progress to display it such as shown the list:

df
  content
0    'None'
1    None
print(df)
  content
0    'None'
1    None

1 Answer 1

1

First of all, in normal cases, there should not be two types of data in one column of a completed DataFrame. Therefore a str and a NoneType cannot show themselves together after data washing.

And in normal cases, we don't want to see so many '' in a string column. It will be annoying. And if you do want to see them, try:

df.content.apply(lambda x: x if not isinstance(x,str) else repr(x))

And the result is what you want:

0    'None' 
1      None  
Name: content, dtype: object
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.