SHARE
TWEET

Untitled

rawplutonium Feb 16th, 2020 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. """
  2. Generate a list of people with their salaries and write that into a csv file.
  3. """
  4. import pandas as pd
  5. import random
  6.  
  7. names = ["John","Peter","Isaiah","George", "Jackson", "James","Mary","Janet","Georgina","Purity","Deborah"]
  8. surnames = ["Mwangi","Omondi","Kipsang","Chege","Kamau","Kyeba","Mariwa","Jones","Ogola","Opiyo","Mwikali"]
  9. salaries = [500*random.randint(10,30) for _ in range(10)]
  10.  
  11.  
  12. def generate_random_person(names, surnames, salaries):
  13.     return {"name": random.sample(names,1)[0],
  14.             "surname": random.sample(surnames,1)[0],
  15.             "salary": random.sample(salaries,1)[0]}
  16.  
  17. def generate_people(k):
  18.     return [generate_random_person(names, surnames, salaries) for _ in range(k)]
  19.  
  20.  
  21. df = pd.DataFrame(generate_people(50), columns=["name", "surname", "salary"])
  22. df.to_csv("random_people.csv")
  23. df = pd.read_csv("random_people.csv")
  24. print(df)
  25. df.describe()
  26. df.dtypes()
  27. df.head()
  28. df.tail()
  29. df.columns
  30. df.sort_index(axis=1, ascending=True)
  31. df2 = df.copy()
  32. import matplotlib.pyplot as plt
  33. plt.plot(df['name'],df['salary'])
  34. ax = plt.axes()
  35. scatter = plt.scatter(df['name'],df['salary'])
  36. df.plot()
  37. df.to_excel('salaries.xlsx', sheet_name='Salaries')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top