Advertisement
_LINKI

DataScience Task2 - Python

Nov 16th, 2019
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | None | 0 0
  1. import numpy as np
  2. import pandas as pd
  3.  
  4. def findMaxPrimeNum(array):
  5.   return array[array % 2 == 0].max()
  6. # Test1
  7. print(findMaxPrimeNum(np.arange(0, 99, 3)))
  8.  
  9. def findZeroPrefixMax(array):
  10.   return array[list(filter(lambda i: array[i + 1] == 0 and array[i] != 0, range(0, array.size - 1)))].max()
  11. # Test2
  12. array = np.array([6, 2, 0, 3, 0, 0, 5, 7, 0])
  13. print(findZeroPrefixMax(array))
  14.  
  15. def getSuperDuperRepeatArray(array):
  16.   return np.repeat(array, array)
  17. # Test3
  18. print(getSuperDuperRepeatArray(np.array([0, 1, 2, 3, 4, 5])))
  19.  
  20. def getPolyderPolynomValueOfX(vector, x):
  21.   return np.polyval(np.polyder(np.poly(vector)), x)
  22. # Test4
  23. print(getPolyderPolynomValueOfX(np.array([3, 4, 7]), 1))
  24.  
  25. def isEqualSumColumnsAndTables(array):
  26.   return np.all(array.sum(axis=0) == array.sum(axis=1))
  27. # Test5
  28. print(isEqualSumColumnsAndTables(np.array([[1, 1], [1, 1]])))
  29.  
  30. def getCorrectDataFrame(dataFrame):
  31.   return dataFrame.where(dataFrame != None, 0)
  32. # Test 6
  33. print(getCorrectDataFrame(
  34.   pd.read_csv('road_data.csv',
  35.   sep = ',', header = 0, names =
  36.   ['cars', 'accidents', 'vodka', 'crime', 'income', 'retail']
  37. )))
  38.  
  39. def getFilteredDataFrame(dataFrame):
  40.   return dataFrame[
  41.   (dataFrame.accidents > 150) &
  42.   ((dataFrame.vodka > 10) | (dataFrame.crime > 1000))
  43.   ].sort_values('accidents', ascending=0)
  44. # Test 7
  45. print(getFilteredDataFrame(pd.read_csv('road_data.csv',
  46.   sep = ',', header = 0, names =
  47.   ['cars', 'accidents', 'vodka', 'crime', 'income', 'retail']
  48. )))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement