Information and facts are major asset in digital world. Data is fuel that is running this world. However, everything is not required by everyone. Only specific part of data is relevant for certain use cases.

Thus filtering data becomes important. By filtering we can filter data as per requirement and generate pattern and knowledge to drive this digital world.

import pandas as pd
import numpy as np
df1 = pd.DataFrame(np.random.randn(5,5),index=['a','b','c','d','e'],columns=['A','B','C','D','E'])
print (df1)

filtered_df = df1[df1['A']>0]
print(filtered_df)

Iterating Pandas DataFrame

for item in df.iterrows():
    print(item)

Merge, Append and Concat operation in Pandas DataFrame

DataFrame comes with feature to merge, concatenate. They are important and useful feature.

import pandas as pd
import numpy as np
df1 = pd.DataFrame(np.random.randn(5,5),index=['a','b','c','d','e'],columns=['A','B','C','D','E'])
print (df1)


df2 = pd.DataFrame(np.random.randn(5,5),index=['a','b','c','d','e'],columns=['A','B','C','D','E'])
print (df2)

df3 = pd.merge(df1,df2)
print(df3)

append is function that allows us to add rows to existing DataFrame

import pandas as pd
import numpy as np
df1 = pd.DataFrame(np.random.randn(5,5),index=['a','b','c','d','e'],columns=['A','B','C','D','E'])
print (df1)


df2 = pd.DataFrame(np.random.randn(5,5),index=['a','b','c','d','e'],columns=['A','B','C','D','E'])
print (df2)

df3 = df1.append(df2)
print(df3)

df4 = pd.concat([df1,df2]) #concat by row
print (df4)

Keep practising, keep learning.

Hope it helps!

🙂

Leave a Reply