Skip to content

Instantly share code, notes, and snippets.

View lakshay-arora's full-sized avatar
🇮🇳

Lakshay lakshay-arora

🇮🇳
  • Walmart
  • Bengaluru
View GitHub Profile
data.groupby(['name', pd.Grouper(key='date', freq='M')])['ext price'].sum()
data.groupby(['name', pd.Grouper(key='date', freq='M')])['ext price'].sum().unstack()
%matplotlib notebook
import matplotlib.pyplot as plt
# scatter plot of some data # try this on your dataset
plt.scatter(data['quantity'],data['unit price'])
%%time
def myfunction(x) :
for i in range(1,100000,1) :
i=i+1
%load_ext rpy2.ipython
%R require(ggplot2)
import pandas as pd
df = pd.DataFrame({
'Class': ['A', 'A', 'A', 'V', 'V', 'A', 'A', 'A'],
'X': [4, 3, 5, 2, 1, 7, 7, 5],
'Y': [0, 4, 3, 6, 7, 10, 11, 9],
'Z': [1, 2, 3, 1, 2, 3, 1, 2]
})
%%R -i df
ggplot(data = df) + geom_point(aes(x = X, y= Y, color = Class, size = Z))
# importing libraries
import pandas as pd
data = pd.read_csv('school.csv')
data.head()
# save the top cities in a list
top_cities = ['Brooklyn','Bronx','Manhattan','Jamaica','Long Island City']
# use loc to update the target
data.loc[(data.City.isin(top_cities) == False),'City'] = 'Others'
# city value counts
data.City.value_counts()
# importing required libraries
import pandas as pd
import math
import multiprocessing as mp
from random import randint
# function to calculate the number of divisors
def countDivisors(n) :
count = 0
for i in range(1, (int)(math.sqrt(n)) + 1) :