Python Pandas 7 examples of filters and lambda apply
https://blog.softhints.com/python-pan...
Python pandas dataframes
show all
count values in pandas dataframe
count rows of pandas dataframe
filter pandas dataframe
python apply lambda expression on pandas dataframe
Example
import pandas as pd
foo = [{
'Language': 'Python',
'Percent grow': 56
}, {
'Language': 'Java',
'Percent grow': 34
}, {
'Language': 'C',
'Percent grow': 25
}, {
'Language': 'C++',
'Percent grow': 12
}, {
'Language': 'go',
'Percent grow': 5
}]
df = pd.DataFrame(foo, index=pd.RangeIndex(0, len(foo)))
print(df)
print('--------------')
print(df['Language'])
print('--------------')
print(df['Language'] == 'Java')
print('--------------')
print(df.loc[df['Language'].isin(['Java','C'])])
print('--------------')
mylambda = lambda x: x in ['C', 'C++']
print(df.loc[df['Language'].apply(mylambda)])
print('--------------')
print(df.loc[df['Language'].apply(lambda x: x in ['C', 'C++'] )])
---------------------------------------------------------------------------------------------------------------------------------------------------------------
Code store
https://bitbucket.org/softhints/
Socials
Facebook: / 435421910242028
Facebook: / softhints
Twitter: / softwarehints
Discord: / discord
If you really find this channel useful and enjoy the content, you're welcome to support me and this channel with a small donation via PayPal.
PayPal donation https://www.paypal.me/fantasyan