Snippets Collections
c3 = pd.Series(['China', 'US'])
df[df['countries'].isin(c1)]
# applying filter function 
df.filter(["Name", "College", "Salary"]) 

# importing pandas as pd 
import pandas as pd 
  
# Creating the dataframe  
df = pd.read_csv("nba.csv") 
  
# Using regular expression to extract all 
# columns which has letter 'a' or 'A' in its name. 
df.filter(regex ='[aA]') 
(df.groupby('name')['ext price']
 .agg(['mean', 'sum'])
 .style.format('${0:,.2f}'))
'${:,.2f}'.format(dfCombined['Amount'].sum())
df['column_name'] = pd.to_datetime(df['column_name'])
# new version
df.groupby(pd.Grouper(key='column_name', freq="M")).mean().plot()
def ffill_cols(df, cols_to_fill_name='Unn'):
    """
    Forward fills column names. Propagate last valid column name forward to next invalid column. Works similarly to pandas
    ffill().
    
    :param df: pandas Dataframe; Dataframe
    :param cols_to_fill_name: str; The name of the columns you would like forward filled. Default is 'Unn' as
    the default name pandas gives unnamed columns is 'Unnamed'
    
    :returns: list; List of new column names
    """
    cols = df.columns.to_list()
    for i, j in enumerate(cols):
        if j.startswith(cols_to_fill_name):
            cols[i] = cols[i-1]
    return cols
bookmark
dashboard

Sat Oct 31 2020 00:55:40 GMT+0000 (UTC) https://stackoverflow.com/questions/19960077/how-to-filter-pandas-dataframe-using-in-and-not-in-like-in-sql

#pandas #isin #filter
bookmark
dashboard

Sat Oct 31 2020 00:40:59 GMT+0000 (UTC) https://www.geeksforgeeks.org/python-pandas-dataframe-filter/

#pandas #filter #column
bookmark
dashboard

Sat Oct 31 2020 00:38:58 GMT+0000 (UTC) https://www.geeksforgeeks.org/python-pandas-dataframe-filter/

#pandas #filter
bookmark
dashboard

Mon Oct 26 2020 01:01:58 GMT+0000 (UTC) https://pbpython.com/styling-pandas.html

#python #pandas #format #currency
bookmark
dashboard

Mon Oct 26 2020 00:28:49 GMT+0000 (UTC) https://www.kite.com/python/answers/how-to-format-a-float-as-currency-in-python

#python #pandas #formatting
bookmark
dashboard

Fri Oct 23 2020 04:54:30 GMT+0000 (UTC) https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.drop_duplicates.html

#pandas #duplicates #drop
bookmark
dashboard

Tue Oct 20 2020 09:28:55 GMT+0000 (UTC) https://www.kite.com/python/answers/how-to-reorder-columns-in-a-pandas-dataframe-in-python

#python #pandas
bookmark
dashboard

Fri Oct 16 2020 22:26:07 GMT+0000 (UTC) https://stackoverflow.com/questions/47015886/pandas-grouper-vs-time-grouper

#python #pandas #grouper
bookmark
dashboard

Thu Aug 06 2020 08:57:00 GMT+0000 (UTC)

#python #pandas #data-cleaning

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension