Last active
February 20, 2018 10:49
-
-
Save shilpavijay/3075f91bd8d792165acb5e840c19e9ae to your computer and use it in GitHub Desktop.
Pandas, Numpy
This file contains 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
#If this is set to True, the axes which are reduced are left in the result as dimensions with size one | |
<np array>.sum(axis=1, keepdims=True) | |
np.vstack - stack array row-wise | |
#Convert to NP Array: | |
df = pd.read_csv(csvfile) | |
nparr = np.array(df) | |
#finding max of a dataframe | |
pd.DataFrame.max(df) | |
#selection on rows and columns: | |
df.loc[:3,['2003','2005']] | |
#index | |
df.set_index('Country', inplace=True) | |
#select row based on row name: | |
df.loc['rowname'] | |
df.loc[['Assam','Karnataka'],['2003','2004']] #i.e. [[rownames],[colnames]] | |
#select row based on a value in the column: | |
df.loc[df['column_name'] == some_value_in_the_table | |
#fill NaN | |
df = df.fillna(0) | |
#get max of all values in the dataframe: | |
df.values.max() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment