%config InlineBackend.figure_format = 'retina'
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set()
pd.set_option("display.max_rows", 8)
plt.rcParams['figure.figsize'] = (9, 6)
pd.Series([1,3,5,np.nan,6,8], dtype=np.float64)
import numpy.random as npr
pd.Series(npr.random(8),
index=pd.period_range('09/11/2017', '09/18/2017', freq="D"),
dtype=np.float64)
from time import sleep
for i in range(10):
sleep(0.1)
print(i, end="\r")
import lorem
data = lorem.text()
words = data.lower().replace(".","").replace("\n"," ").split()
res = {}
current_word = None
for word in sorted(words):
if current_word == word:
res[word] +=1
else:
res[word] = 1
current_word = word
sorted(res.items(), key=lambda w:-w[1])
Counter(words).most_common()
words = data.split()
def f(word):
return (word.lower(),1)
list(map(f, words))
list(filter(lambda word: word.startswith("e"), words))
res = []
for word in words:
if word.startswith("e"):
res.append(word)
res
[ word for word in words if word.startswith("e")]
sorted(filter(lambda w: len(w)>0, data.replace(".", "").lower().split()))
from collections import Counter
import lorem
data = lorem.text()
words = data.lower().replace(".","").replace("\n"," ").split()
result = {w:c for w,c in Counter(words).most_common()}
df = pd.Series(result)
df
df.plot(kind="bar")
df.loc['dolore']
print(df.dolore)
print(df['dolore'])
print(df.iloc[-1])
df.sort_values().plot(kind='bar')
df.sort_index().plot(kind='bar')
import os
here = os.getcwd()
filename = os.path.join(here,"data","monthly.land.90S.90N.df_1901-2000mean.dat.txt")
df = pd.read_table(filename, sep="\s+",
names=["year", "month", "mean temp"])
df
import os
here = os.getcwd()
filename = os.path.join(here,"data","monthly.land.90S.90N.df_1901-2000mean.dat.txt")
df = pd.read_table(filename, sep="\s+",
names=["year", "month", "mean temp"])
df.insert(2, 'day', 1)
df.index = pd.to_datetime(df[['year','month','day']])
temp = df['mean temp']
temp
temp.head()
temp.tail()
new_temp = temp.copy()
new_temp[ temp.values == -999] = np.nan
new_temp.tail()
new_temp = new_temp.dropna()
new_temp.tail()
new_temp.plot()
new_temp = temp.copy()
new_temp[ temp.values == -999] = np.nan
new_temp = new_temp.dropna()
new_temp = new_temp.to_period('M')
new_temp.resample('1A').mean().plot()
with pd.HDFStore("data/pandas_series.h5") as writer:
df.to_hdf(writer, "/temperatures/full_globe")
with pd.HDFStore("data/pandas_series.h5") as store:
df = store["/temperatures/full_globe"]