matplotlib基础
plt.plot(first_twelve['DATE'], first_twelve['VALUE'])
plt.xticks(rotation=45)
plt.xlabel('Month')
plt.ylabel('Unemployment Rate')
plt.title('Monthly Unemployment Trends, 1948')
plt.legend(loc='best')
画子图:
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(3, 3))
ax1 = fig.add_subplot(3,2,1)
ax2 = fig.add_subplot(3,2,2)
ax3 = fig.add_subplot(3,2,6)
ax1.plot(…)
ax2.plot(…)
ax3.plot(…)
plt.show()
先生成一个画布(fig),然后生成一系列子图,ax1,ax2,ax3,然后操作ax进行绘图,最后show出来画布(fig)
Pandas
food_info = pandas.read_csv("food_info.csv")
food_info.dtypes
food_info.head(3)
food_info.tail(4)
food_info.columns
food_info.shape
col_names = food_info.columns.tolist()
Selection by Label
df.loc
df.loc[:,[‘A’,’B’]]
df.loc[‘20130102’:’20130104’,[‘A’,’B’]]
Selection by Position
df.iloc[3:5,0:2]
df.iloc[[1,2,4],[0,2]]
Boolean Indexing
df[df.A > 0]
df[df > 0]
df2[df2[‘E’].isin([‘two’,’four’])]
Setting a new column
s1=pd.Series([1,2,3,4,5,6], index=pd.date_range(‘20130102’, periods=6));df[‘F’] = s1;
df.loc[:,’D’] = np.array([5] * len(df))
df2[df2 > 0] = -df2
单个赋值
df.iat[0,1] = 0
df.at[dates[0],’A’] = 0
缺失值处理
df1.dropna(how=’any’)
df1.fillna(value=5)
pd.isna(df1)
new_titanic_survival =