Skip to content

Instantly share code, notes, and snippets.

View pygaurav's full-sized avatar
🎯
Focusing

Gaurav Bhardwaj pygaurav

🎯
Focusing
View GitHub Profile
@pygaurav
pygaurav / filtering_data_pandas.py
Created June 26, 2019 19:20
Filtering Data with Pandas
import pandas as pd
column_names = ["sepal length","sepal width","petal length","petal width","Type of flower"]
df = pd.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data",
names=column_names)
df[(df['sepal length']>6) & (df['petal length']>5 )]
@pygaurav
pygaurav / selected_rows_loc_pandas.py
Created June 26, 2019 19:12
Selected Rows loc pandas
import pandas as pd
column_names = ["sepal length","sepal width","petal length","petal width","Type of flower"]
df = pd.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data",
names=column_names,index_col="sepal length")
#Lets see the dataframe with index as sepal length
print(df.head())
#Lets verify indexes
print(df.index)
#This will return all rows with index -> sepal length 5.0
@pygaurav
pygaurav / selected_rows_iloc_pandas.py
Last active June 26, 2019 19:11
Selected Rows ILOC Pandas
import pandas as pd
column_names = ["sepal length","sepal width","petal length","petal width","Type of flower"]
df = pd.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data",
names=column_names)
#This will return all rows with indexes 2-4
print(df.iloc[2:5,:].head())
@pygaurav
pygaurav / selected_columns_pandas.py
Created June 26, 2019 18:54
Selected Columns Pandas Python
import pandas as pd
column_names = ["sepal length","sepal width","petal length","petal width","Type of flower"]
df = pd.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data",
names=column_names)
#Creating the selected column list
select_column_names=["sepal width","petal length"]
#Printing selected columns by loc way
@pygaurav
pygaurav / basic_functions_pandas.py
Created June 26, 2019 18:20
Basic Functions Pandas
import pandas as pd
column_names = ["sepal length","sepal width","petal length","petal width","Type of flower"]
df = pd.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data",
names=column_names)
print("The shape of dataframe is {0}".format(df.shape))
print("The dimension of dataframe is {0}".format(df.ndim))
print("The size of dataframe is {0}".format(df.size))
print("The dtype of data is {0}".format(df.dtypes))
print("The values of data is {0}".format(df.values))
@pygaurav
pygaurav / dimension_dataframe.py
Created June 26, 2019 18:07
dimension dataframe
import pandas as pd
column_names = ["sepal length","sepal width","petal length","petal width","Type of flower"]
df = pd.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data",
names=column_names)
df.shape
@pygaurav
pygaurav / iris_describe.py
Created June 26, 2019 17:56
Pandas Iris Describe
import pandas as pd
column_names = ["sepal length","sepal width","petal length","petal width","Type of flower"]
df = pd.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data",
names=column_names)
df.describe()
@pygaurav
pygaurav / pandas_iris_dataset_import.py
Created June 24, 2019 16:04
Pandas - Reading a Iris Dataset
import pandas as pd
column_names = ["sepal length","sepal width","petal length","petal width","Type of flower"]
df = pd.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data",
names=column_names)
df.head()
@pygaurav
pygaurav / pandas_dataframes_part1.py
Last active June 24, 2019 15:36
Pandas Dataframe Part1
import pandas as pd
list_of_numbers1 = [100,200,300,400,500]
index_number1 = [1,2,3,4,5]
list_of_numbers2 = [200,300,400,500,600]
index_number2 = [10,20,30,40,50]
series1 = pd.Series(data=list_of_numbers1,index=index_number1)
series2 = pd.Series(data=list_of_numbers2,index=index_number2)
@pygaurav
pygaurav / pandas_series_index_dissimilar.py
Created June 24, 2019 14:36
Pandas Series: Different Indexes
import pandas as pd
list_of_numbers1 = [100,200,300,400,500]
index_number1 = [1,2,3,4,5]
list_of_numbers2 = [200,300,400,500,600]
index_number2 = [10,20,30,40,50]
series1 = pd.Series(data=list_of_numbers1,index=index_number1)
series2 = pd.Series(data=list_of_numbers2,index=index_number2)