import pandas as pd
import numpy as np
import datetime
from pylab import *
from pandas.tests.plotting.test_converter import dates
pd.options.display.max_colums = 10
df = pd.read_csv("*.csv")
print(df.shape)
print(df.size)
df.head()
df1 = df.reindex(index=dates[:4],columns=["ABCD"]+["G"])
df1.loc[dates[0]:dates[1],"G"] = 1
print(df1)
print(df1.dropna())
print(df1.fillna(value=2))
print(df.mean)
print(df.var())
s = pd.Series([1,2,4,np.nan,5,7,9,10],index = dates)
print(s)
print(s.shift(2))
print(s.diff())
print(df.apply(np.cumsum))
print(df.apply(lambda x:x.max()-x.min()))
pieces = [df[:3],df[-3:]]
print(pd.concat(pieces))
left = pd.DataFrame({"key":["x","y"],"value":[1,2]})
right = pd.DataFrame({"key":["x","z"],"value":[3,4]})
print("LEFT",left)
print("RIGHT",right)
print(pd.merge(left,right,on="key",how="left"))
df3 = pd.DataFrame({"A",["a","b","c","d"],"B":list(range(4))})
print(df3.groupby("A").sum())
df4 = pd.DataFrame({'A':['one','one','two','three']*6,
'B':['a','b','c']*8
'C':['foo','foo','bar','bar','bar','bar'] * 4,
'D':np.random.randn(24),
'E':np.random.randn(24),
'F':[datetime.datetime(2017,i,1) for i in range(1,13)]+
[datetime.datetime(2017,i,15) for i in range(1,13)]})
print(pd.pivot_table(df4,values="D",index=["A","B"],columns=["C"]))
t_txam = pd.date_range("20170301",periods=10,freq="S")
print(t_txam)
ts = pd.Series(np.random.randn(1000),index = pd.date_range("20170301",periods=1000))
ts = ts.cumsum()
ts.plot()
show()
|