Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Generate a list of people with their salaries and write that into a csv file.
- """
- import pandas as pd
- import random
- names = ["John","Peter","Isaiah","George", "Jackson", "James","Mary","Janet","Georgina","Purity","Deborah"]
- surnames = ["Mwangi","Omondi","Kipsang","Chege","Kamau","Kyeba","Mariwa","Jones","Ogola","Opiyo","Mwikali"]
- salaries = [500*random.randint(10,30) for _ in range(10)]
- def generate_random_person(names, surnames, salaries):
- return {"name": random.sample(names,1)[0],
- "surname": random.sample(surnames,1)[0],
- "salary": random.sample(salaries,1)[0]}
- def generate_people(k):
- return [generate_random_person(names, surnames, salaries) for _ in range(k)]
- df = pd.DataFrame(generate_people(50), columns=["name", "surname", "salary"])
- df.to_csv("random_people.csv")
- df = pd.read_csv("random_people.csv")
- print(df)
- df.describe()
- df.dtypes()
- df.head()
- df.tail()
- df.columns
- df.sort_index(axis=1, ascending=True)
- df2 = df.copy()
- import matplotlib.pyplot as plt
- plt.plot(df['name'],df['salary'])
- ax = plt.axes()
- scatter = plt.scatter(df['name'],df['salary'])
- df.plot()
- df.to_excel('salaries.xlsx', sheet_name='Salaries')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement