Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,987 questions

51,931 answers

573 users

How to create NaN values in multi column Pandas DataFrame in Python

1 Answer

0 votes
import pandas as pd
import numpy as np

data = {'A': [1,2,3,4,np.nan,5,np.nan,np.nan,6,7,8,np.nan],
        'B': [7,8,np.nan,9,np.nan,np.nan,10,12,13,np.nan,11,12],   
        'C': [100,200,300,np.nan,5,np.nan,np.nan,0,8,np.nan,np.nan,99]
       }

df = pd.DataFrame(data,columns=['A', 'B', 'C'])

print(df)



 
 
'''
run:
 
     A     B      C
0   1.0   7.0  100.0
1   2.0   8.0  200.0
2   3.0   NaN  300.0
3   4.0   9.0    NaN
4   NaN   NaN    5.0
5   5.0   NaN    NaN
6   NaN  10.0    NaN
7   NaN  12.0    0.0
8   6.0  13.0    8.0
9   7.0   NaN    NaN
10  8.0  11.0    NaN
11  NaN  12.0   99.0

'''

 



answered Jan 12, 2021 by avibootz
...