top of page
Search

Introduction to Pandas and Matplotlib | LBOET | HOXFRAMEWORK

Writer: Hox FrameworkHox Framework

Introduction to Pandas and Matplotlib | LBOET | HOXFRAMEWORK


Hello and welcome! In this tutorial we will do a little bit of

data science work using matplotlib and pandas.


Lets get started,

Code 1 :

<!--

import pandas as pd

from matplotlib import *

import matplotlib.pyplot as plt

from matplotlib import style

style.use('fivethirtyeight')




mydataframe = pd.DataFrame({'entries':[34,12,6,6,5,10,10,102,230,215,112]},

index = [4,5,6,7,8,9,10,11,12,13,14])



print(mydataframe)



plt.ylabel("Kills in a videogame")

plt.xlabel("Round")

plt.plot(mydataframe[{'entries'}])


#You can also save it as pdf, or remove the bbox_inches but then it looks too zoomed in

plt.show()



-->

Code 2:

<!--

import pandas as pd




df1 = pd.DataFrame({'Year':[2001,2002,2003,2004],

'Games_won':[2,3,2,2],

'Money_gained':[50,55,65,55]})



df3 = pd.DataFrame({'Year':[2001,2002,2003,2004],

'Games_lost':[7,8,9,6],

'Money_spent':[20,33,19,49]})


merged = pd.merge(df1,df3,on = 'Year',how= 'outer') #or inner ; this is if our data is different

merged.set_index('Year', inplace=True)

print("Videogame stats 2001-2004:\n")

print(merged)


-->

Code 3 (websitehits):

<!--

import csv

from matplotlib import *

import matplotlib.pyplot as plt

from matplotlib import style

import pandas as pd

style.use('fivethirtyeight')


day = []

views = []

with open('views.csv') as csv_file:

csv_reader = csv.reader(csv_file, delimiter=',')

line_count = 0

for row in csv_reader:

if line_count == 0:

print(f'Column names are {", ".join(row)}\n')

#what does this first one do

line_count += 1

else:

#why try?

try:

#

print(f'Day:{row[0]} , Month: {row[1]} , Views: {row[2]}')

#what are we doing here ?

day.append(row[0])

views.append(row[2])

#why dont we need {} ?

line_count += 1

except IndexError:

print("Done.")


mydataframe = pd.DataFrame({'views': views},index = day)


##mydataframe = mydataframe.sort_values(['views'], ascending=1)

##mydataframe = mydataframe.sort_index(ascending=1)



print(mydataframe)

plt.ylabel("Views")

plt.xlabel("Day")

plt.title("Website views per day - January 2019")

plt.plot(mydataframe['views'])

#plt.scatter(day,mydataframe['views'])

plt.savefig('website_hits.png', bbox_inches='tight')

plt.show()

-->


And views.csv:

<!--

day,month,views

1,January,50

2,January,60

3,January,70

4,January,70

5,January,75

6,January,80

7,January,90

8,January,120

9,January,150

10,January,250

11,January,200

12,January,320

13,January,435

14,January,120

15,January,150



-->


Thank you so much for visiting and have a nice day. :)

 
 
 

Recent Posts

See All

Commentaires


©2019 by Hox Framework. Proudly created with Wix.com

bottom of page