Skip to main content

Posts

MongoDB #1 - View Databases, Create a database, collection, and insert a document, View documents

MongoDB Tutorial Step1: Install MongoDB on computer Step2: Start MongoDB Step3: Create databases, collections, and documents using the following commands. To view all databases show dbs To use 'students' database use students To view all databases show dbs To insert a document in 'students' database in 'studentData' collection db.studentData.insertOne({"name":"Vinit", "YearsOfExperience":4, "PostGraduate":true}, {"name":"Khandelwal", "YearsOfExperience":6, "PostGraduate":false} ) Get all records from a database collection db.studentData.find().pretty()

Pandas Operations - Unique, Value Counts, Apply, Drop, Columns, Index, Sort Values, Is Null, Pivot Tables - Python

Pandas Operations - Unique, Nunique, Value Counts, Apply, Drop, Columns, Index, Sort Values, Is Null, Pivot Tables Run the python code here:  https://repl.it/@VinitKhandelwal/pandas-operations import numpy as np import pandas as pd df = pd.DataFrame ({ 'col1' :[ 1 , 2 , 3 , 4 ], 'col2' :[ 1111 , 2222 , 3333 , 2222 ], 'col3' :[ 'aaa' , 'bbb' , 'ccc' , 'ddd' ]}) print ( df ) print ( "LIST OF UNIQUE VALUES IN A COLUMN" ) print ( df [ 'col2' ] .unique ()) print ( "COUNT OF UNIQUE VALUES IN A COLUMN" ) print ( df [ 'col2' ] .nunique ()) print ( "COUNT OF VALUES IN A COLUMN" ) print ( df [ 'col2' ] .value_counts ()) print ( "CONDITIONAL SELECTION" ) print ( df [( df [ 'col1' ] > 2 ) & ( df [ 'col2' ] < 3333 )]) print ( df [ 'col1' ] > 2 ) print ( "APPLY" ) def times2 ( x ): return x* ...

Concatenation, Merging, and Joining in Pandas - Python

Here is how to concatenate, merge, or join in Pandas Run the python code here:  https://repl.it/@VinitKhandelwal/pandas-concat-merge-join import numpy as np import pandas as pd print ( "CONCAT" ) df1 = pd.DataFrame ( np.random.randn ( 4 , 4 ), [ 0 , 1 , 2 , 3 ], [ 'A' , 'B' , 'C' , 'D' ]) print ( df1 ) df2 = pd.DataFrame ( np.random.randn ( 4 , 4 ), [ 4 , 5 , 6 , 7 ], [ 'A' , 'B' , 'C' , 'D' ]) print ( df2 ) df3 = pd.DataFrame ( np.random.randn ( 4 , 4 ), [ 8 , 9 , 10 , 11 ], [ 'A' , 'B' , 'C' , 'D' ]) print ( df3 ) print ( pd.concat ([ df1 , df2 , df3 ])) df1 = pd.DataFrame ( np.random.randn ( 4 , 4 ), [ 0 , 1 , 2 , 3 ], [ 'A' , 'B' , 'C' , 'D' ]) print ( df1 ) df2 = pd.DataFrame ( np.random.randn ( 4 , 4 ), [ 0 , 1 , 2 , 3 ], [ 'E' , 'F' , 'G' , 'H' ]) print ( df2 ) df3 ...

Missing Data and GroupBy Function in Pandas - Python

Here is how to play with missing data and use groupby function in Pandas. Run the code here:  https://repl.it/@VinitKhandelwal/pandas-groupby import numpy as np import pandas as pd print ( "MISSING DATA" ) d = { 'A' :[ 1 , 2 , np.nan ], 'B' :[ 4 , np.nan , np.nan ], 'C' :[ 7 , 8 , 9 ]} print ( d ) df = pd.DataFrame ( d ) print ( df ) print ( "DROP ROWS" ) print ( df.dropna ()) print ( "DROP COLUMNS" ) print ( df.dropna ( axis= 1 )) print ( "DROP ROWS WITH THRESHHOLD" ) print ( df.dropna ( thresh= 2 )) print ( df.fillna ( value= "Fill Value" )) print ( df.fillna ( value=df.mean ())) print ( "GROUP BY" ) data = { 'Company' :[ 'GOOG' , 'GOOG' , 'MSFT' , 'MSFT' , 'FB' , 'FB' ], 'Person' :[ 'Sam' , 'Charlie' , 'Amy' , 'Vanessa' , 'Carl' , 'Sarah' ], 'S...

Functionalities of Dataframes in Pandas - Python

Functionalities of Dataframes in Pandas Run the code here:  https://repl.it/@VinitKhandelwal/pandas-dataframes import numpy as np import pandas as pd print ( np.random.seed ( 101 )) df = pd.DataFrame ( np.random.randn ( 5 , 4 ),[ 'A' , 'B' , 'C' , 'D' , 'E' ],[ 'W' , 'X' , 'Y' , 'Z' ]) # defining data frame - 1st arg: matrix data, 2nd arg: rows, 3rd arg: columns print ( df ) # print data frame print ( type ( df )) # Type of data frame print ( df [ 'W' ]) # Python style, recommended print ( type ( df [ 'W' ])) # Type of a column print ( df.W ) # SQL style, not recommended print ( df [[ 'W' , 'Z' ]]) # pass list of column names for multipe columns but not all columns print ( "ADD NEW COLUMN" ) df [ 'V' ] = df [ 'W' ] +df [ 'Z' ] print ( df [ 'V' ]) print ( df ) print ( "DROP COLUMN" ) df....