Last active
August 18, 2019 17:53
-
-
Save vikas-git/3340402087fa158a68234402da803312 to your computer and use it in GitHub Desktop.
Important Query for Pandas Dataframe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# search with and/or condition | |
df4 = df3.query('(From=="AHH" & To=="BBH") | (From=="BBH" & To=="AHH")') | |
OR | |
data.loc[(data["Gender"]=="Female") & (data["Education"]=="Not Graduate") & (data["Loan_Status"]=="Y"), ["Gender","Education","Loan_Status"]] | |
# Rows to columns | |
df = df.stack().reset_index().rename(columns={'level_0':'From','level_1':'To', 0:'Hours'}) | |
# Join two df like sql join | |
df1 = df1.merge(record_df, on='location_code', how='outer', suffixes=('_x', '_y')) | |
# concate multiple df's | |
master_df = pd.concat([master_df, df], ignore_index=True | |
# applymap function | |
df.applymap(lambda x:x*2) | |
# add new column in df | |
df.assign(Score3 = [56,86,77,45,73,62,74,89,71]) | |
# df date string to pandas date object | |
df['date'] = pd.to_datetime(df['date']) | |
OR | |
df = pd.read_csv('file.csv', parse_dates=['Date']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment