<jupyter_start><jupyter_text>Series Basics<jupyter_code>ser = pd.Series(data = np.random.randint(1,200,26),index=[x for x in string.ascii_lowercase])
df.head()
ser.head()
s = pd.Series(data = {'Sammy':5,'Frank':10,'Spike':7}) # automatically assign keys as index
s
s['Sammy'] # call my key
s[0]# call by index
q1 = {'Japan': 80, 'China': 450, 'India': 200, 'USA': 250}
q2 = {'Brazil': 100, 'India': 210,'USA': 260,'China': 500}
data1 = pd.Series(data=q1)
data2 = pd.Series(data =q2)
data1
data2
data1 + data2 # automatically finds missing and puts null in uncomman nan + data = nan
data1.add(data2,fill_value = 0)  #automatically finds missing and puts 0 in uncomman 0+data = data
data1.sub(data2,fill_value = 0)
data1*2 # broadcasting
data1/2
data1.add_prefix('hello')
data1.aggregate(func=np.mean)<jupyter_output><empty_output><jupyter_text>DataFrames<jupyter_code>df.head()
df.describe() # all continous columns 
df.info()
len(df)
df1 = pd.DataFrame(data=np.random.randint(2,200,(5,5)),index=['a','b','c','d','e'],columns=['a','b','c','d','e'])
df.index
df.columns<jupyter_output><empty_output><jupyter_text>Selection and Indexing* 1 Column* 2 rows<jupyter_code>df['tip'].head(3)
df.loc[2] # all values of second row 'use if named index'
df.iloc[2] # use if numeric index
df = df.set_index('Payment ID')
df.head(2)
df.loc['Sun2959']
df.iloc[0]
df = df.reset_index()
df[['tip','CC Number']].head()
df.iloc[[0,1,2]][['tip','CC Number']]
df.drop([0,1],axis=0).head()
df.drop('Payment ID', axis=1).head(3)<jupyter_output><empty_output><jupyter_text>conditional Filtering<jupyter_code># 1 single condition
# 2 multiple condition 

df[df['tip']>7]
# and &
# or |
# not ~
df[(df['tip']>5) & (df['sex'] == 'Female') & (df['smoker']=='Yes')]
options = ['Yes','Male','Sun',5]

df[df['sex'].isin(options) & df['smoker'].isin(options)].head()<jupyter_output><empty_output><jupyter_text>Apply<jupyter_code>def tips(x):
    return np.round(x)
df['tip'].apply(tips)
df['tip'].apply(lambda x : np.round(x))
def take(x,y):
    return x+y
df[['tip','total_bill']].apply(lambda df : take(df['tip'],df['total_bill']),axis=1)
df['total']= np.vectorize(take)(df['tip'],df['total_bill'])
df.sort_values('tip',ascending=False).head(2)
df.value_counts('time') # used for cateogires
df.corr()
df.max()
df.min()
df['total'].idxmax()
df.iloc[170]
df['sex'].replace(['Female','Male'],['F','M'])
d = {'Female':'F' , 'Male' : 'M'}
df['sex'].map(d)
df['time'].unique()
df['time'].nunique()
df.nlargest(5,columns=['tip','price_per_person'],keep = 'all')
df['tip'].between(2,3,inclusive = True)
simple_df = pd.DataFrame([1,2,2],['a','b','c'])
simple_df
simple_df.duplicated()
simple_df.drop_duplicates()<jupyter_output><empty_output><jupyter_text>Missing Values* Keep null* drop null* replace null<jupyter_code>df = pd.read_csv('C:\\Users\\<NAME>\\OneDrive\\Desktop\\python_basic\\Ml\\00 ml_course\\DATA\\movie_scores.csv')

df.isnull() # Similar to df.isna()
df.notna() # similar to df.notnull()
df[df['first_name'].notna()]
df.dropna() # drop all null
df.dropna(how = 'all')
df.dropna(how='any')
df
df.fillna(value = 'x',axis = 1)
df['first_name'].fillna('name',inplace=True)
df
df['pre_movie_score'].interpolate()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.22363919129082427, 'fraction_numerical': 0.03203732503888025, 'mean_word_length': 7.396866840731071, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '489411', 'license': 'Apache-2.0', 'n_tokens_mistral': 1377, 'n_tokens_neox': 1290, 'n_words': 223, 'path': '02 Pandas/Revision_01.ipynb', 'repo_name': 'ketangangal/Ml_Projects', 'size': '3221'}