<jupyter_start><jupyter_text>Reg. No         Name         Marks1000            Winner       901001            Emeto        85<jupyter_code>pd.DataFrame(data,index,columns,dtype,copy)
df = pd.DataFrame()
df
data = [1,2,3,4,5]
df = pd.DataFrame(data)
df
data = [['Alex',10],['Bob',12],['Winner',13]]
df = pd.DataFrame(data,columns=['Name','Age'])
df
data = {'Name':['Tom','Jack','Winner','Joy'], 'Age':[28,34,20,22]}
df = pd.DataFrame(data)
df
data = [{'a':1,'b':2,'c':5},{'a':4,'b':5,'c':6}]
df = pd.DataFrame(data)
df
data = [{'a':1,'b':2,'c':5},{'a':4,'b':5,'c':6,'d':8}]
df = pd.DataFrame(data,index=['first','second'])
df
data = {'one':pd.Series([1,2,3,4], index=['a','b','c','d']), 'two':pd.Series([4,5,6,7], index=['a','b','c','d'])}
df = pd.DataFrame(data)
df
df['one']
df['two']
df['three'] = pd.Series([10,20,40],index=['a','b','c'])
df
del df['one']
df
df.iloc[0]
df.iloc[-1]
df.loc['a']
df.loc['d']
df = pd.DataFrame([[1,2],[3,4]],columns=['a','b'])
df2 = pd.DataFrame([[5,6],[7,8]],columns=['a','b'])
print(df)
print('==============')
print(df2)
df3 = df.append(df2)
df3
df4 = df3.drop(0)
df4
N = 20

df = pd.DataFrame({
    'A':pd.date_range(start='2016-01-01',periods=N,freq='D'),
    'X':np.linspace(0,stop=N,num=N),
    'Y':np.random.rand(N),
    'C':np.random.choice(['low','Medium','High'],N).tolist(),
    'D':np.random.normal(100,10,size=(N)).tolist()
})

df
df_reindex = df.reindex(index=[0,2,7,3,5],columns=['A','C','B'])
df_reindex
for item in df:
    print(item)
df = pd.DataFrame(np.random.randn(4,3),columns=['col1','col2','col3'])
df
for key,value in df.iteritems():
    print(key,value)
for row_index,row in df.iterrows():
    print(row_index, row)
df
unsorted_df = pd.DataFrame(np.random.randn(10,2),index=[1,4,6,2,3,5,9,8,0,7],columns=['col2','col1'])
unsorted_df
sorted_label = unsorted_df.sort_index()
sorted_label
unsorted_df.sort_values(by='col1')
unsorted_df.sort_index(axis=1)
sorted_label = unsorted_df.sort_index(ascending=False)
sorted_label
df = pd.DataFrame(np.random.randn(5,3),index=['a','b','e','f','h'], columns=['one','two','three'])

df = df.reindex(['a','b','c','d','e','f','g','h'])
df
df['one'].isnull()
df.fillna(0)
df.dropna()
df.dropna(axis=1)
df = pd.DataFrame([[1,2,3],[5,4,6],[7,8,9],[np.nan,np.nan,np.nan]], columns=['S','P','A'])
df
df.agg(['sum','min','max'])
ipl_data = {'Team': ['Riders', 'Riders', 'Devils', 'Devils', 'Kings',
   'kings', 'Kings', 'Kings', 'Riders', 'Royals', 'Royals', 'Riders'],
   'Rank': [1, 2, 2, 3, 3,4 ,1 ,1,2 , 4,1,2],
   'Year': [2014,2015,2014,2015,2014,2015,2016,2017,2016,2014,2015,2017],
   'Points':[876,789,863,673,741,812,756,788,694,701,804,690]}
df = pd.DataFrame(ipl_data)

print(df)
df.groupby('Team')
df.groupby('Team').groups
df.groupby(['Team','Year']).groups
df_grouped = df.groupby('Year')
df_grouped.groups
df_grouped.get_group(2014)
df_grouped.get_group(2017)
df
df_grouped['Points'].agg(np.mean)<jupyter_output><empty_output><jupyter_text>pd.merge(left, right, how='inner', on=None, left_on=None, right_on=None,left_index=False, right_index=False, sort=True)<jupyter_code>left = pd.DataFrame({
    'id':[1,2,3,4,5],
    'Name':['Alex','Winner','Joy','Mercy','Alice'],
    'Subject_ID':['sub1','sub2','sub3','sub4','sub5']
})
left
right = pd.DataFrame({
    'id':[1,2,3,4,5],
    'Name':['Billy','Emeto','Bran','Brain','Betty'],
    'Subject_ID':['sub2','sub4','sub3','sub6','sub5']
})
right
pd.merge(left,right,on='id')
pd.merge(left,right,on='Subject_ID',how='left')
pd.merge(left,right,on='Subject_ID',how='right')
pd.merge(left,right,on='Subject_ID',how='inner')
pd.concat([left,right])
left
right
pd.Timedelta('2 days 2 hours 15 minutes 30 seconds')
data = pd.Series(['a','b','c','a','d','e','c','d'], dtype='category')
print(data)
df = pd.DataFrame(np.random.randn(10,4),index=pd.date_range('1/1/2021',periods=10), columns=list('ABCD'))
df
df.plot()
df = pd.DataFrame(np.random.rand(10,4),columns=['a','b','c','d'])
df
df.plot.bar()
df = pd.DataFrame(np.random.rand(10,5),columns=['A','B','C','D','E'])
df
df.plot.box()
df = pd.DataFrame(3*np.random.rand(4),index=['a','b','c','d'], columns=['x'])
df
df.plot.pie(subplots=True)<jupyter_output><empty_output><jupyter_text>S.No,Name,Age,City,Salary1,Tom,28,Toronto,200002,Lee,32,HongKong,30003,Steven,43,Bay Area,83004,Ram,38,Hyderabad,3900<jupyter_code>df = pd.read_csv('WB-GDP-2013.csv')
df
df['country']
df['year']
df = pd.read_excel('WHO POP TB all.xls')
df
df.iloc[4]
df['Country']
df = pd.read_excel('WHO POP TB all.xls', sheet_name='Winner')
df
df['Country']
df.iloc[3]
df
df.to_excel('test.xlsx')
df.to_excel('test.xlsx',index=False)
df.to_excel('test.xlsx',index=False,sheet_name='Winner Sheet')
df.to_csv('test-file.csv')
df.to_excel('test.xlsx',index=False,sheet_name='Winner2 Sheet')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.27487458193979936, 'fraction_numerical': 0.06647157190635451, 'mean_word_length': 7.747714808043876, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '152028', 'license': 'MIT', 'n_tokens_mistral': 2290, 'n_tokens_neox': 2126, 'n_words': 253, 'path': 'Pandas.ipynb', 'repo_name': 'oluwatosinehindero/DataScienceClass', 'size': '4784'}