Python Data Wranglings

It refers to the technique where we process the data and clean the data for further use.as we know that data comes from the various sources and this type of the data is very bulky and incomplete, Python performs the operations to clean the data.

Data Merging

Merging function use the process with data, here we can merge ,group the data lets understand by the program

Program

# import the pandas library
import pandas as abc
#left side dataframe creating
l = abc.DataFrame({
         'Sr':[1,2,3],
         'Name': ['Ram', 'Shyam', 'Mohan'],
         'Stream':['Science','Commerce','Art']})
#left side dataframe creating
r = abc.DataFrame(
         {'Sr':[1,2,3],
         'Name': ['Reema', 'Seema', 'Pooja'],
         'Stream':['Science','Commerce','Art']})
print(l)
print(r)

Output

Sr   Name    Stream
0   1    Ram   Science
1   2   Shyam  Commerce
2   3   Mohan       Art
Sr   Name    Stream
0   1  Reema   Science
1   2  Seema  Commerce

Concatenating Data

Concat function is used to perform th concat two dataframe and series


Output

   Sr   Name    Stream
0   1    Ram   Science
1   2  Shyam  Commerce
2   3  Mohan       Art
0   4  Reema   Science
1   5  Seema  Commerce
2   6  Pooja       Art

Grouping Data

Data is available many form and much time data duplicacy exist in data,pandas help to group the data let’s take the demonstration.

Program

# import the pandas library
import pandas as pd
#creating dataframe
student_data = {'Student': ['Ram ', 'Shaym', 'Mohan', 'Sohan', 'Seeta',
         'Geeta'],
         'Ad': [2007,2005, 2006, 2007,2006,2005],
         'clas': [7,7,5,5,4,4],
         'Stream':["Science","Commerce","Art","Math","Science","Art"]}
df = pd.DataFrame(student_data)

grouped = df.groupby('Ad')
print(grouped.get_group(2007))

Output

Student    Ad  clas   Stream
0    Ram   2007     7  Science
3   Sohan  2007     5     Math
Subscribe Now