Advertisement
class_connect

Full-Day Session on NumPy and Pandas 13/5/24

May 13th, 2024 (edited)
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.66 KB | None | 0 0
  1. *Important Links
  2. https://colab.research.google.com/drive/1XVMnEW26FJbMqhzkUNVEAO54UV_jRUbi?usp=sharing#scrollTo=gLb8Q7LGF9dY
  3. https://colab.research.google.com/drive/1dYskioKSgaTFWgIq7U6hfNKtFgmWRC2C?usp=sharing#scrollTo=0t9FYcLUEWqQ
  4. https://colab.research.google.com/drive/13x6Rw-IINKaT6enR9iVqzxfkFgWEvPyu?usp=sharing
  5. https://www.kaggle.com/competitions
  6.  
  7. #NumPy
  8. import numpy as np
  9. from numpy.random import default_rng
  10. nums = default_rng().integers(low=-10000, high=10000, size=10000) #generate
  11. print(nums) #the randomly generated array
  12. print(nums.shape) #displays the shape of the randomly generated array
  13. if (nums == 2).any(): #to find the number 2 by iterating through the array
  14.    print((nums == 2)) #displays the boolean values
  15.    print((nums == 2).sum()) #displays the number of times found (sum all True)
  16.    print((nums != 2).sum()) #displays the number of times not found (sum False)
  17.  
  18.  
  19.  
  20. #Panda
  21. import pandas as pd
  22. '''mydataset = {
  23.  'cars': ["BMW", "Volvo", "Ford","RoyalEnfield"],
  24.  'passings': [3, 7, 2, 4]
  25. }'''
  26.  
  27. #myvar = pd.DataFrame(mydataset)
  28.  
  29. #print(myvar.tail(1))
  30. #print(myvar['cars'][0])
  31. #print(myvar.shape)
  32. #print(myvar.info())
  33. #print(myvar.describe())
  34.  
  35. file_name = "iris.txt"
  36. df = pd.read_csv(file_name)
  37. #print(df.head())
  38. #species = df["species"].unique()
  39. #print(species)
  40. #df[df["species"] == 'setosa'] = 1
  41. #df[df["species"] == 'versicolor'] = 2
  42. #df[df["species"] == 'virginica'] = 3
  43. #plt.plot(kind="scatter", x="species", y="petal_width")
  44. #print(df.plot(kind="hist", x="species", y="petal_width"))
  45. print(df.shape)
  46. a = df.dropna()
  47. print(df.shape)
  48. print(a.shape)
  49. b = df.dropna(subset=['petal_length', 'species'])
  50. print(b.shape)
  51.  
  52.  
  53.  
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement