skaljic1
9/11/2017 - 5:49 PM

pandas_library_python

pandas_library_python

# To get value of 1 row
df.at[0,'A']
# To get all value in array
df.values 
# From to index and column name
df.iloc[0:7,0:3] 
# Chosing with list
df.iloc[[2,4,5,6,7],[2,3]] 
# Chosing row by value of column:
something = df_test3.loc[df_test3['club'] == 'LIVERPOOL V MAN UTD']
#Taking value from 1 column and converting it to a list
c_df = pd.DataFrame(all_in_one[country])
ar_names = c_df.iloc[:,2].values
#sort
df_intertops.sort_values(by='club', inplace=True)
#reset index
df_bet365.reset_index(drop=True, inplace=True)
#concat
result = pd.concat(frames, axis=1, join='outer')
#Making new column with calculation (%)
df_previous['percentage'] = df_previous['number']/sum(df_previous['number'])*100
#applying function without argument
df = df.apply(function) 
#replacing values
df_ultimate_frame.replace('what', 'with that', inplace=True)
#Pandas pickle save and load
import pickle
df_ultmate_frame_ENGFACUP.to_pickle('practice.pickle')
df_pickle = pd.read_pickle('practice.pickle')
#Pandas if else 
df.loc[df.AAA >= 5,'BBB'] = -1 #For 1 column
df.loc[df.AAA >= 5,['BBB','CCC']] = 555 #For more columns
#Creating dummies
dummies = pd.get_dummies(df['Sex'], drop_first=True)
#Renaming column
dummies.columns = ['Sex(male = 1)']
#Deleting column
del df['column']
#Multiple condition if (| &)
df = df[(df['rate(1,2x)'] != 'N/A') | (df['rate(x,12)'] != 'N/A') | (df['rate(2,1x)'] != 'N/A')]
#Filter with lambda
df[df['style'].apply(lambda x: function(str(x)))][['tag','style']]