|
import pandas as pd
import numpy as np
col = [ 'col1','col2', 'col3' ,'col4']
row = [ 'row1','row2', 'row3' ]
data = [[ 1 , 2 , pd.NA , 4 ],
[np.nan, 6 , np.inf , 8 ],
[ 9 , ' ' , '' , None ]]
df = pd.DataFrame(data,row,col)
print(df,'\n')
# col1 col2 col3 col4
#row1 1.0 2 <NA> 4.0
#row2 NaN 6 inf 8.0
#row3 9.0 NaN
print(' isna',df.isnull(),'\n') # isna == isnull
# isna col1 col2 col3 col4
#row1 False False True False
#row2 True False False False
#row3 False False False True
print('notna',df.notna() ,'\n') # notna == notnull
#notna col1 col2 col3 col4
#row1 True True False True
#row2 False True True True
#row3 True True True False
df.at['row4','col5']=45
df.at['row5','col7']=57
print(df,'\n')
# col1 col2 col3 col4 col5 col7
#row1 1.0 2 <NA> 4.0 NaN NaN
#row2 NaN 6 inf 8.0 NaN NaN
#row3 9.0 NaN NaN NaN
#row4 NaN NaN NaN NaN 45.0 NaN
#row5 NaN NaN NaN NaN NaN 57.0
print(' index:',df.index,'\n')
# index: Index(['row1', 'row2', 'row3', 'row4', 'row5'], dtype='object')
print('columns:',df.columns,'\n')
#columns: Index(['col1', 'col2', 'col3', 'col4', 'col5', 'col7'], dtype='object') |
|