Skip to content

Instantly share code, notes, and snippets.

View vinaykudari's full-sized avatar
💭
lets talk code

Vinay vinaykudari

💭
lets talk code
View GitHub Profile
list_a, list_b = zip(*zipped_object)
>> list_a
(1, 2, 3, 4, 5)
>> list_b
('a', 'b', 'c', 'd', 'e')
@vinaykudari
vinaykudari / rand_seed.py
Created July 24, 2018 10:19
Random Seed
np.random.seed(25) #setting a seed
print(np.random.rand(3))
>> [0.87012414 0.58227693 0.27883894]
np.random.seed(25)
print(np.random.rand(3))
>> [0.87012414 0.58227693 0.27883894]
print(np.random.rand(3))
>> [0.52071879 0.32605113 0.69918624]
a = np.arange(4)
print(a,'\n')
>> [0 1 2 3]
b = np.reshape(a,(2,2))
print(b, '\n')
>> [[0 1]
[2 3]]
c = b.reshape(4)
a = np.arange(4).reshape((2,2))
for i in np.nditer(a):
print(i)
>> 0
1
2
3
a = np.arange(2,10,2)
print(a)
>> [2 4 6 8]
print(a>5)
>> [False False True True]
b = np.flatnonzero(a>1)
print(b)
>> [2 3]
ages = np.random.randint(10,50,10)
heights = np.random.randint(120,210,10)
>> ages
[24 22 13 26 31 20 29 32 34 19]
>> heights
[146 141 166 191 169 203 149 135 170 152]
sorter = np.argsort(ages)
a = np.random.randint(5,10,5)
>> a
[6 5 8 8 7]
np.add.at(a,np.flatnonzero(a>8),2) #flatnonzero returns the indices where values are >8
>> a
[6 5 10 10 9]
np.maximum.at(a,[0,1,2],60) #checks the max value
>> a
@vinaykudari
vinaykudari / importing_data.ipynb
Last active July 25, 2018 22:59
Importing Data
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vinaykudari
vinaykudari / pd_melting.ipynb
Last active July 26, 2018 16:10
Melting Data
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import pandas as pd
time_format = '%Y-%m-%d %H%M%S'
date = ['2015-01-01 091234','2015-01-01 091234']
time_format_date = pd.to_datetime(date,format=time_format)
print(time_format_date)
>> DatetimeIndex(['2015-01-01 09:12:34', '2015-01-01 09:12:34'], dtype='datetime64[ns]', freq=None)