3-1 Pandas-概述
Pandas章节应用的数据可以在以下链接下载:
https://files.cnblogs.com/files/AI-robort/Titanic_Data-master.zip
Pandas:数据分析处理库¶
In [1]:
import pandas as pd
In [4]:
df=pd.read_csv('./Titanic_Data-master/Titanic_Data-master/train.csv')
.head():可以读取前几条数据,或指定前几条都可以
In [5]:
df.head(6)
Out[5]:
.info():返回当前的信息
In [6]:
df.info()
查看表格的各项属性和细节¶
In [7]:
df.index#索引值的属性
Out[7]:
In [8]:
df.columns#每一列的名字
Out[8]:
In [9]:
df.dtypes#每一列的值的类型
Out[9]:
In [10]:
df.values#每行的值
Out[10]:
自己创建data_frame数据
In [11]:
data={'country':['aaa','bbb','ccc'],'population':[10,12,14]}
df_data=pd.DataFrame(data)
df_data
Out[11]:
In [12]:
df_data.info()
In [15]:
age=df['Age']#搜索对应的一列
age[:5]#显示前5行数据
Out[15]:
series:dataframe中的一行/列
In [16]:
age.index
Out[16]:
In [17]:
age.values[:5]
Out[17]:
In [18]:
df.head()
Out[18]:
In [19]:
df['Age'][:5]
Out[19]:
改变索引对象
In [20]:
df=df.set_index('Name')
df.head()
Out[20]:
In [21]:
df['Age'][:5]
Out[21]:
In [25]:
age=df['Age']
age[:5]
Out[25]:
In [26]:
age['Allen, Mr. William Henry']#索引名字对应的值
Out[26]:
In [27]:
age=age+10
age[:5]
Out[27]:
对值统计指标
In [28]:
age.mean()
Out[28]:
In [29]:
age.max()
Out[29]:
In [30]:
age.min()
Out[30]:
In [31]:
df.describe()####整体一次性统计各项的指标基本统计特性
Out[31]:
此资源来自https://www.cnblogs.com/AI-robort/,博客园的karina512。