Skip to content

Instantly share code, notes, and snippets.

@kendhia
Created December 18, 2016 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kendhia/d7d47871f165e071b17f1f211353a094 to your computer and use it in GitHub Desktop.
Save kendhia/d7d47871f165e071b17f1f211353a094 to your computer and use it in GitHub Desktop.
import csv
import matplotlib.pyplot as plot
csvReader = csv.reader(open("weather_2012.csv"))
weatherCsvList = list(csvReader)
weatherDic = {}
weatherMeanDegree = []
for i in range(1, len(weatherCsvList)):
if weatherCsvList[i][7] in weatherDic:
weatherDic[weatherCsvList[i][7]].append(float(weatherCsvList[i][1]))
else:
weatherDic[weatherCsvList[i][7]] = [float(weatherCsvList[i][1])]
for key in weatherDic:
meanValue = 0
for i in weatherDic[key]:
meanValue += i
weatherDic[key] = meanValue / len(weatherDic[key])
for key in sorted(weatherDic):
print(key, " ", weatherDic[key])
listOfSortedKeys = sorted(weatherDic)
listOfSortedValues = []
for key in listOfSortedKeys :
listOfSortedValues.append(weatherDic[key])
x_axis = [x for x in range(len(listOfSortedKeys))]
y_axis = listOfSortedValues
plot.bar(x_axis, y_axis, color='y',bottom=-15)
plot.xticks(x_axis, list(weatherDic.keys()), rotation=45, fontsize="5")
plot.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment