Pandas是一个富强的Python数据分析库,供给了疾速、机动、直不雅的数据构造,如DataFrame跟Series,以及丰富的数据分析东西。控制Pandas是成为一名优良数据分析师的必备技能。
import pandas as pd
arr = [0, 1, 2, 3, 4]
df = pd.Series(arr)
dates = pd.date_range('today', periods=6)
numarr = np.random.randn(6, 4)
columns = ['A', 'B', 'C', 'D']
df = pd.DataFrame(numarr, index=dates, columns=columns)
df = pd.read_csv('filename.csv', sep=';', encoding='gbk')
df.dropna() # 删除包含缺掉值的行
df.fillna(value=0) # 用0填充缺掉值
df[(df['price'] > 1000) | (df['minimumnights'] < 1)]
df['date'] = pd.to_datetime(df['date'])
df.drop(['unnecessary_column'], axis=1)
df['income'] = df['price'] * df['numberofreviews']
df.groupby('neighbourhood')['price'].mean()
df['roomtype'] = pd.Categorical(df['roomtype']).codes
df['neighbourhood'].value_counts()
df['price'].describe()
import matplotlib.pyplot as plt
plt.hist(df['price'], bins=20)
plt.show()
import seaborn as sns
sns.scatterplot(x='latitude', y='longitude', data=df)
df.apply(lambda x: x.max())
df.map(lambda x: x * 2)
df.set_index(['neighbourhood', 'roomtype'], inplace=True)
df['income'] = df['price'] * df['numberofreviews']
df['roomtype'] = pd.Categorical(df['roomtype'])
分析纽约市Airbnb房源数据,包含价格、地位、房东信息跟批评数量等字段。
分析股票市场数据,包含收盘价、收盘价、最低价、最便宜跟成交量等字段。
经由过程以上50题的实战剖析,信赖你曾经控制了Pandas的基本操纵、数据清洗、数据处理、数据分析跟数据可视化等技能。退职场挑衅中,Pandas将成为你富强的数据分析东西。