For online Python training registration, click here !
Data frame is the tabular data object in Python. It can store different mode of data for different columns. If you want to remove unwanted columns from a data frame, you can use either del() function or drop() method. Next we show some examples about that.
#Import Pandas module
import pandas as pd
#create a dictionary
Dict4 = {'last' : ['zhang', 'yue', 'lin', 'li', 'wang'],
'first' : ['wei', 'shirley', 'mico', 'miaomiao', 'maomao'],
'age' : [32, 34, 8, 14, 3],
'city': ['molde','aukra','molde','aukra','molde']}
#create a data frame with inputting dictionary above
Df4 = pd.DataFrame(Dict4)
Df4
#output
last first age city
0 zhang wei 32 molde
1 yue shirley 34 aukra
2 lin mico 8 molde
3 li miaomiao 14 aukra
4 wang maomao 3 molde
#delete one column, using del() function
del Df4['first']
Df4
#output
last age city
0 zhang 32 molde
1 yue 34 aukra
2 lin 8 molde
3 li 14 aukra
4 wang 3 molde
#create again same data frame
Df4 = pd.DataFrame(Dict4)
#using drop method to remove two columns
Df4= Df4.drop(['city','age'], axis=1)
Df4
#output
last first
0 zhang wei
1 yue shirley
2 lin mico
3 li miaomiao
4 wang maomao Sometimes you may need the removed column, then you can use pop() method to data frame.
#create again data frame
Df4 = pd.DataFrame(Dict4)
#remove column 'city' and save this to an object.
Pop_col= Df4.pop('city')
#show popped columm, it is a series
Pop_col
#output
0 molde
1 aukra
2 molde
3 aukra
4 molde
Name: city, dtype: object
#show original data frame, the column 'city' has been removed
Df4
#output
last first age
0 zhang wei 32
1 yue shirley 34
2 lin mico 8
3 li miaomiao 14
4 wang maomao 3 For more examples on Python, you can view playlists from our YouTube channel.
To train a PyTorch Transformer for multi-track music generation, the standard paradigm is to convert…
In the field of AI and Natural Language Processing (NLP), The Transformer is the engine…
If your goal is purely symbolic melody generation (e.g., generating MIDI files or notes rather…
According to PyTorch document, In PyTorch, torch.nn.functional.affine_grid generates a 2D or 3D flow field (sampling…
Creating an Android mobile app with a deep learning AI model involves several key steps:…
Click here to go to source files for R Machine Learning