-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMy_Google_Project.py
More file actions
200 lines (126 loc) · 5.71 KB
/
Copy pathMy_Google_Project.py
File metadata and controls
200 lines (126 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 24 20:08:14 2022
@author: dell
"""
"""
Created on Sun Apr 21 10:16:34 2022
@author: Aman.Verma
"""
##########################################################################################
#------------------------------------Pandas In Python-------------------------------------#
##########################################################################################
import pandas as pd
import numpy as np
import os
#Setting the working directory
os.chdir(R'C:\Users\dell\Documents\PYTHON_SCRIPTS\PANDAS')
path_data = os.getcwd()
#Master_Path
path_data= R'C:\Users\dell\Documents\PYTHON_SCRIPTS\PANDAS'
print(path_data)
#Branch_Path
input_path = os.path.join(path_data,"input")#Sub Folder1
output_path = os.path.join(path_data,"output")#Sub Folder 2
#------------------------------------------CSV---------------------------------------#
employee_df = pd.read_csv(os.path.join(input_path,"employees.csv"))
GoogleData = pd.read_csv("Googleplaystore_1.csv")
##########################################################################################
#3.Viewing Data
##########################################################################################
#Head of Data
GoogleData.head()
First_100=GoogleData.head(100)
#Tail of Data
GoogleData.tail()
Last_10=GoogleData.tail(10)
#Viewing the Columns of Data
GoogleData.columns
#Checking the Structure of Data
GoogleData.dtypes
# Print the info of Data
print(GoogleData.info())
#Summary of the Data
Des=GoogleData.describe()
#Including all the Data Levels
Des_all=GoogleData.describe(include='all')
#GoogleData_1 = GoogleData[(GoogleData.Category == "FAMILY")]
# Print the shape of Data
print(GoogleData.shape)
##########################################################################################
#4.Changing the type of data
##########################################################################################
#Converting a coloumn to a particular Data Type
pd.to_numeric(GoogleData.Rating)
#Multiple Columns
GoogleData_1=GoogleData.copy()
GoogleData_1.dtypes
#Univariate changes
GoogleData_1["Rating"] = GoogleData_1["Rating"].apply(str)
GoogleData_1["Rating"] = GoogleData_1["Rating"].apply(float)
#Multivariate changes
GoogleData_1[["Rating","Reviews"]] = GoogleData_1[["Rating","Reviews"]].apply(str)#Making same changes across columns
GoogleData_1 = GoogleData_1.astype({"Rating":'str',"Reviews":'float'})#Making different changes across columns
GoogleData_1.dtypes
##########################################################################################
#5.Selecting the Data
##########################################################################################
#Selecting only one Column
GoogleData1= GoogleData['App']
GoogleData1= GoogleData[['App','Rating','Reviews','Category']]
GoogleData1= GoogleData.App
#Selecting only Multiple Columns
col_list = ['App','Category','Rating','Reviews']
GoogleData2= GoogleData[col_list]
#Based on Labels
GoogleData2= GoogleData.loc[:,'App']# All Rows
GoogleDat2= GoogleData.loc[200:300,['App','Size','Reviews']]
GoogleDat2.shape
#Based on Index
GoogleData2= GoogleData.iloc[:,[2,3,10]]
#Selecting Multiple Rows
GoogleData2= GoogleData.iloc[0:3,:]
GoogleData2_iloc= GoogleData.iloc[0:3,3:10]
GoogleData2_loc = GoogleData.loc[0:3,['App','Size']]
##########################################################################################
#6. Filtering the Data
##########################################################################################
GoogleData3 = GoogleData[GoogleData.Rating == 3].reset_index(drop=True)
GoogleData3 = GoogleData[GoogleData.Rating == 3]
GoogleData3 = GoogleData[GoogleData['Rating'] > 3]
#AND
GoogleData4 = GoogleData[(GoogleData.Rating > 3) & (GoogleData.Reviews > 10000 )].reset_index(drop=True)
#OR
GoogleData5 = GoogleData[(GoogleData.Rating > 3) | (GoogleData.Reviews > 10000 ) ]
#AND & OR
GoogleData5 = GoogleData[((GoogleData.Rating > 3) & (GoogleData.Reviews > 10000 )) | (GoogleData.Category == "ART_AND_DESIGN")]
GoogleData6 = GoogleData[GoogleData['Category'].isin(["ART_AND_DESIGN","HEALTH_AND_FITNESS"])]
#NOT
GoogleData4 = GoogleData[(GoogleData.Rating > 3) & ~(GoogleData.Reviews > 10000 )]
#MULITPLE NOT
GoogleData4 = GoogleData[~(GoogleData.Rating ==3) & ~(GoogleData.Reviews > 10000 )]
GoogleData4.to_csv(os.path.join(output_path,"Processed_Google_Data.csv"),index=False)
##########################################################################################
#7. Working with Missing Data
##########################################################################################
#pandas primarily uses the value np.nan to represent missing data
#Finding the columns with Missing Values
Miss = GoogleData.isnull().sum()
Miss_df = pd.DataFrame({'Missing_Value_Count':GoogleData.isnull().sum()}).reset_index()
#Total Sum of Missing Values
GoogleData.isnull().sum().sum()
#Imputing Missing values withe particular value
GoogleData7=GoogleData.fillna(value=0)
Miss = print(GoogleData7.isnull().sum())
#Working with particular columns
GoogleData7=GoogleData.copy()
GoogleData7['index']=GoogleData7.index
GoogleData7['Rating'] = GoogleData7['Rating'].fillna((GoogleData7['Rating'].mean()))
#Filtering based on odd rows
GoogleData7_odd = GoogleData7[::3]#N-1
GoogleData7_odd = GoogleData7[::2]
#Filterinf based on even rows
GoogleData7_even = GoogleData7[1::2]
#Append two data frames in Pandas
GoogleData8=GoogleData7.head(10).append(GoogleData7.tail(10)).reset_index(drop=True)
GoogleData8=GoogleData7.head(10).append([GoogleData7.tail(10),GoogleData7.tail(2)])