Notesatfingerbyvrinda.files.wordpress.com
DATAFRAME FROM DICTIONARY OF SERIESimport pandas as pdd = {'one' : pd.Series([1, 2, 3], index=['a', 'b', 'c']), 'two' : pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])}df1 = pd.DataFrame(d)print(df1)#How to see the type of columns?#print(df1.dtypes)#Selecting data column wiseprint("\n\nSelecting column one")print(df1['one'])#Adding a new column to an existing DataFrameprint("Method1")df1['three']=pd.Series([1,2,3,4],index=['a', 'b', 'c', 'd'])print("\n\nAfter adding column three")print(df1)print("Method2")df1.loc[:,'four']=[1,2,3,4]print("\n\nAfter adding column four using loc")print(df1)print("Method3")df1.at[:,'five']=[1,2,3,4]print("\n\nAfter adding column five using at")print(df1)print("Method4")df1=df1.assign(six=[1,2,3,4])print("\n\nAfter adding column six using assign")print(df1)#Deleting one columnprint("After deleting column three using pop")df1.pop('three')print(df1)print("After deleting column four using del")del df1['four']print(df1)#selecting row and modifying itprint(df1.loc['a'])print(df1.iloc[2])df1.loc[['a'],['two']]=55print("after modifying one data in the index a\n")print(df1)#slicing rowprint(df1[1:3])#adding new rowsd = {'one' : pd.Series([11, 22, 33], index=['a', 'b', 'c'])}df2 = pd.DataFrame(d)df3=df1.append(df2)print("The new dataframe df2\n",df2)print("\n\nAfter appending \ndf3\n",df3)print("\n\nAfter appending \ndf1\n",df1)#deleteing rowdf=df3.drop('a')print("\n\nAfter deleting \ndf\n",df)print("\n\nAfter deleting \ndf3\n",df3)#Renaming row and columndfnew=df1.rename(columns={'one':'ONE','two':'TWO'},index={'a':0})print(dfnew)#head and tail functionsprint(df1.head(1))print(df1.tail(1))print(df1) ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
Related searches
- wordpress passing data between pages
- wordpress business templates
- wordpress rss feed not working
- wordpress jquery is not defined
- create wordpress blog
- wordpress roles editor
- wordpress full rss feed
- wordpress rss feed settings
- wordpress rss feed plugin
- wordpress display rss feed
- wordpress rss feed link
- wordpress rss feed to post