Skip to content

Instantly share code, notes, and snippets.

View GurjotSinghMahi's full-sized avatar
🏢
Working from Office

Gurjot Singh Mahi GurjotSinghMahi

🏢
Working from Office
  • Punjabi University, Patiala, Punjab, India
  • Chandigarh
View GitHub Profile
@GurjotSinghMahi
GurjotSinghMahi / Array Traversing
Created January 24, 2015 06:41
C++ demonstration of Array Traversing Algorithm
#include<iostream>
using namespace std;
int main()
{
int arr[20],range,n;
cout<<"enter the range of elements"<<endl;
cin>>range; //input the range of items to be inserted
cout<<"enter the array"<<endl;
for(n=0;n<range;n++)
cin>>arr[n]; //input the item in array
@GurjotSinghMahi
GurjotSinghMahi / Binary search
Created January 24, 2015 06:44
C++ Performing Binary search
pip install pandas
pip install tabulate
import pandas as pd
from tabulate import tabulate
import pandas as pd
from tabulate import tabulate
# read the csv file
df = pd.read_csv("raw_data.csv")
# displaying the DataFrame
print(tabulate(df, headers = 'keys', tablefmt = 'psql'))
# read the csv file and parse the dates
df = pd.read_csv("raw_data.csv", parse_dates=['SubmissionDate', 'starttime', 'endtime'])
# Remove Time from SubmissionDate Column
df['Date'] = pd.to_datetime(df['SubmissionDate']).dt.date
print(tabulate(df[['Date', 'SubmissionDate']], headers = 'keys', tablefmt = 'psql'))
# Select the dataframe greater than mentioned date
start_date = '2020-12-04'
df['Date'] = (df['Date']).astype('datetime64[D]')
#select only particular date data
df = df.loc[((df['Date'] >= start_date))]
# Prin the dataframe
print(tabulate(df[['SubmissionDate', 'user_id', 'gadget']], headers = 'keys', tablefmt = 'psql'))
# Set start and end date
start_date = '2020-12-04'
end_date = '2020-12-07'
# Define datatype
df['Date'] = (df['Date']).astype('datetime64[D]')
#select only particular date data
df = df.loc[((df['Date'] >= start_date) & (df['Date'] <= end_date))]
# Print the dataframe
print(tabulate(df[['SubmissionDate', 'user_id', 'gadget']], headers = 'keys', tablefmt = 'psql'))
# Convert Date to respective day name
df['Date'] = (df['Date']).astype('datetime64[D]')
# convert Date to day name
df['Day'] = df['Date'].dt.day_name()
df['Date'] = pd.to_datetime(df['Date']).dt.date
# Print the dataframe
print(tabulate(df[['Date', 'Day', 'user_id', 'gadget']], headers = 'keys', tablefmt = 'psql'))