Pandas DataFrame Attributes

TTranspose , Changing Columns and indexes
atvalue at input row , column
columnsName of the Columns as List
dtypesData types of columns
emptyChecking if DataFrame is empty
iatData at position ( integer based )given as row and column
ilocData at (label based )
indexDetails on row based
is_copyReturn the copy ( deprecated)
ixData based on row and column ( deprecated)
locData based on (label based ) Position
ndimDimension ( axis ) of the DataFrame
shapeNumber of rows and column as tuple
sizeNumber of elements in DataFrame
styleAssociated HTML style
valuesNumpy representation of the DataFrame
List all attributes and methods of Pandas module by using dir()
import pandas as pd
print(dir(pd))
Use this code for examples of all sample attributes shown below.
import pandas as pd 
my_dict={'NAME':['Ravi','Raju','Alex','Ron','King','Jack'],
         'ID':[1,2,3,4,5,6],'MATH':[30,40,50,60,70,80],'ENGLISH':[20,30,40,50,60,70]}
my_data = pd.DataFrame(data=my_dict)
print(my_data)
Python DataFrame We can print the output here
   NAME  ID  MATH  ENGLISH
0  Ravi   1    30       20
1  Raju   2    40       30
2  Alex   3    50       40
3   Ron   4    60       50
4  King   5    70       60
5  Jack   6    80       70
Above code will be used to check different attributes

T

T :Transpose , Changing Columns and indexes
print(my_data.T)
            0     1     2    3     4     5
NAME     Ravi  Raju  Alex  Ron  King  Jack
ID          1     2     3    4     5     6
MATH       30    40    50   60    70    80
ENGLISH    20    30    40   50    60    70

at

at : value at by row, column pair
print(my_data.at[3,'ENGLISH']) # 50 

columns

columns: Name of the Columns
print(my_data.columns) 
Output
Index(['NAME', 'ID', 'MATH', 'ENGLISH'], dtype='object')

dtypes

dtypes : dtypes of used DataFrame
print(my_data.dtypes)
Output
NAME       object
ID          int64
MATH        int64
ENGLISH     int64
dtype: object
More on Data Types: dtypes()

empty

empty : The DataFrame empty or not ( True or False )
print(my_data.empty) # False 

iat

iat : Value at position at rows and columns as integers ( inputs ).
print(my_data.iat[2,3]) # 40

iloc

iloc Values at different Positions , More on iloc

index

index : Details on row labels
print(my_data.index) # RangeIndex(start=0, stop=6, step=1)

is_copy

is_copy : deprecated

ix

ix : deprecated , position based on row and column
print(my_data.ix[2,'MATH']) # 50 

loc

loc : Values , More on loc

ndim

ndim : array dimensions or axes
print(my_data.ndim) #2

shape

shape : Tuple giving dimension of DataFrame as ( rows, columns )
print(my_data.shape) # (6,4)

size

size : Number of elements in the DataFrame
print(my_data.size) #24
Details on shpe size and ndim

style

style : Associated html style
print(my_data.style)

values

values : All values of the DataFrame without axes labels. Numpy representation of the DataFrame.
print(my_data.values)
Output is here
[['Ravi' 1 30 20]
 ['Raju' 2 40 30]
 ['Alex' 3 50 40]
 ['Ron' 4 60 50]
 ['King' 5 70 60]
 ['Jack' 6 80 70]]
Pandas DataFrame Pandas Methods
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer