1、 np.percentile(train_list["wnum1"], [10, 90, 95, 99])  计算一个多维数组的任意百分比分位数,此处的百分位是从小到大排列

2、fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(20, 6)) 定义画图的画布

  - 在画图时,要注意首先定义画图的画布:fig = plt.figure( ) 
  - 然后定义子图ax ,使用 ax= fig.add_subplot( 行,列,位置标) 
  - 当上述步骤完成后,可以用 ax.plot()函数或者 df.plot(ax = ax) 
  - 在jupternotebook 需要用%定义:%matplotlib notebook;如果是在脚本编译器上则不用,但是需要一次性按流程把代码写完; 
  - 结尾时都注意记录上plt.show()

DataFrame.plot( )函数具体解释:https://blog.csdn.net/brucewong0516/article/details/80524442

3、train_list.plot(kind="hist", y=["wnum1", "wnum2"], bins=20, alpha=0.5, density=True, ax=ax1)

  kind代表的图的类型,hlist是柱状图

bins代表柱状图有几个柱子,设置为20,默认是10

  alpha 代表填充的不透明度  0-1取值

4、ax1.legend()

  显示图例

5、train_unique_q = np.concatenate([train_data["q2"].unique(), train_data["q1"].unique()]) 

  示例:

  >>> a=np.array([1,2,3])
  >>> b=np.array([11,22,33])
  >>> c=np.array([44,55,66])
  >>> np.concatenate((a,b,c),axis=0)  # 默认情况下,axis=0可以不写
  array([ 1,  2,  3, 11, 22, 33, 44, 55, 66]) #对于一维数组拼接,axis的值不影响最后的结果

6、from collections import Counter 

  train_question = np.concatenate([train_data["q1"], train_data["q2"]])
  test_question = np.concatenate([test_data["q1"], test_data["q2"]])
  train_counter = Counter(train_question)
  test_counter = Counter(test_question)
  print(train_counter.most_common(10))
  print(test_counter.most_common(10))

输出:

[('Q489328', 112), ('Q119369', 109), ('Q632400', 109), ('Q382228', 108), ('Q081677', 107), ('Q555455', 107), ('Q149996', 105), ('Q436579', 105), ('Q143237', 105), ('Q424359', 104)]
[('Q066137', 34), ('Q209532', 31), ('Q526780', 31), ('Q665740', 29), ('Q405292', 28), ('Q092597', 28), ('Q195819', 26), ('Q150486', 26), ('Q263180', 26), ('Q492945', 25)]

  counter工具用于支持便捷和快速地计数

7、words = questions["words"].str.split(" ").tolist()

8、from gensim.corpora import Dictionary

  word_dict = Dictionary(words)
  char_dict = Dictionary(chars)

  dictionary.id2token      结果:{0: 'human', 1: 'interface', 2: 'computer', 3: 'survey', 4: 'user'}

dictionary.token2id      结果:{'human': 0, 'interface': 1, 'computer': 2, 'survey': 3, 'user': 4, 'system': 5, ..................}

  dictionary.dfs    结果:{0: 2, 1: 2, 2: 2, 3: 2, 4: 3, 5: 3, 6: 2, 7: 2, 8: 2, 9: 3, 10: 3, 11: 2}

  参考博客:https://blog.csdn.net/qq_19707521/article/details/79174533

9、char_df = pd.concat([char_series, char_prop], axis=1)

10、train_list = train_data.merge(questions, how="left", left_on="q1", right_on="qid").drop("qid", axis=1)

11、

  train_list = train_data.merge(questions, how="left", left_on="q1", right_on="qid").drop("qid", axis=1)
  train_list.head()
  train_list = train_list.rename(columns={"words": "w1", "chars": "c1"})
  train_list = train_list.merge(questions, how="left", left_on="q2", right_on="qid").drop("qid", axis=1)
  train_list = train_list.rename(columns={"words": "w2", "chars": "c2"})
  train_list["wnum1"] = train_list["w1"].map(len)
  train_list["cnum1"] = train_list["c1"].map(len)
  train_list["wnum2"] = train_list["w2"].map(len)
  train_list["cnum2"] = train_list["c2"].map(len)
  train_list["wboth"] = train_list.apply(lambda x: len([t for t in x["w1"] if t in x["w2"]]), axis=1)
  train_list["cboth"] = train_list.apply(lambda x: len([t for t in x["c1"] if t in x["c2"]]), axis=1)
  train_list.head()

12、label = train_data["label"].values.copy()  值的复制

13、question_feature = total_question.value_counts().reset_index()       

  value_counts确认数据出现的频率  注意:from collections import Counter  Counter()函数也能计数,返回值格式可能不一致

  .reset_index 是改变index,重置index

14、

  unique_question = total_question.drop_duplicates().reset_index(drop=True)
  question_dict = pd.Series(unique_question.index,unique_question).to_dict()

  注释:.drop_duplicates() 去重     .reset_index()重置index      series.to_dict()转换为字典、

15、 from keras.preprocessing.text import Tokenizer

  char_tokenizer = Tokenizer()
  char_tokenizer.fit_on_texts(question_data["chars"])
  char_tokenizer.word_index

使用Tokenizer的方法是,首先用Tokenizer的 fit_on_texts 方法学习出文本的字典,然后word_index 就是对应的单词和数字的映射关系dict,通过

这个dict可以将每个string的每个词转成数字

16、word_count = sorted(list(word_tokenizer.word_counts.items()), key=lambda x: x[1], reverse=True)

  lambda是一个隐函数,是固定写法,不要写成别的单词;x表示列表中的一个元素,在这里,表示一个元组,x只是临时起的一个名字,你可以使用任意的名字;x[0]表

  示元组里的第一个元素,当然第二个元素就是x[1];所以这句命令的意思就是按照列表中第一个元素排序

    items() 函数以列表返回可遍历的(键, 值) 元组数组

  reverse=true参数实现倒序排列

17、data["word_same"] = data.apply(lambda x: len(set(x["words1"]).intersection(set(x["words2"]))), axis=1)

  解释:假设a,b为两个list 
    1、交集

    list(set(a).intersection(set(b)))

    2、并集

    list(set(a).union(set(b)))

    3、差集(list a中有,而list b中没有的)

    list(set(a).difference(set(b)))

18、word_embedding_data = pd.read_csv(WORD_EMBED_PATH, delimiter=" ", header=None, index_col=0)

分隔符为空格、列表头为none、列的索引去第0列

  

数据分析,numpy pandas常用api记录的更多相关文章

  1. 数据分析——Numpy/pandas

    NumPy NumPy是高性能科学计算和数据分析的基础包.部分功能如下: ndarray, 具有矢量算术运算和复杂广播能力的快速且节省空间的多维数组. 用于对整组数据进行快速运算的标准数学函数(无需编 ...

  2. #2 numpy pandas初步学习记录

    对numpy中的array进行了了解,array方法的取值arr_2d[0:2, 0:2] pandas 1,read_CSV方法 2,head方法 3,loc方法,取值前开后开, 4,replace ...

  3. Python数据分析与挖掘所需的Pandas常用知识

    Python数据分析与挖掘所需的Pandas常用知识 前言Pandas基于两种数据类型:series与dataframe.一个series是一个一维的数据类型,其中每一个元素都有一个标签.series ...

  4. NumPy和Pandas常用库

    NumPy和Pandas常用库 1.NumPy NumPy是高性能科学计算和数据分析的基础包.部分功能如下: ndarray, 具有矢量算术运算和复杂广播能力的快速且节省空间的多维数组. 用于对整组数 ...

  5. python 数据分析工具之 numpy pandas matplotlib

    作为一个网络技术人员,机器学习是一种很有必要学习的技术,在这个数据爆炸的时代更是如此. python做数据分析,最常用以下几个库 numpy pandas matplotlib 一.Numpy库 为了 ...

  6. 常用统计分析python包开源学习代码 numpy pandas matplotlib

    常用统计分析python包开源学习代码 numpy pandas matplotlib 待办 https://github.com/zmzhouXJTU/Python-Data-Analysis

  7. Python数据分析--Numpy常用函数介绍(2)

    摘要:本篇我们将以分析历史股价为例,介绍怎样从文件中载入数据,以及怎样使用NumPy的基本数学和统计分析函数.学习读写文件的方法,并尝试函数式编程和NumPy线性代数运算,来学习NumPy的常用函数. ...

  8. Pandas常用操作方法

    Pandas pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的. Pandas 纳入了大量库和一些标准的数据模型,提供了高效地操作大型数据集所需的工具. pandas提 ...

  9. 4、numpy+pandas速查手册

    <Python数据分析常用手册>一.NumPy和Pandas篇 一.常用链接: 1.Python官网:https://www.python.org/2.各种库的whl离线安装包:http: ...

随机推荐

  1. Flask Jinja2 知识点

    Jinja2模板引擎使用以下分隔符从HTML转义. {% ... %}用于语句 {{ ... }}用于表达式可以打印到模板输出 {# ... #}用于未包含在模板输出中的注释 # ... ##用于行语 ...

  2. TensorFlow从0到1之浅谈感知机与神经网络(18)

    最近十年以来,神经网络一直处于机器学习研究和应用的前沿.深度神经网络(DNN).迁移学习以及计算高效的图形处理器(GPU)的普及使得图像识别.语音识别甚至文本生成领域取得了重大进展. 神经网络受人类大 ...

  3. 阿里P7终于讲完了JDK+Spring+mybatis+Dubbo+SpringMvc+Netty源码

    前言 这里普及一下,每个公司都有职别定级系统,阿里也是,技术岗以 P 定级,一般校招 P5, 社招 P6 起.其实阅读源码也是有很多诀窍的,这里分享几点心得: 首先要会用.你要知道这个库是干什么的,掌 ...

  4. 黎活明8天快速掌握android视频教程--23_网络通信之网络图片查看器

    1.首先新建立一个java web项目的工程.使用的是myeclipe开发软件 图片的下载路径是http://192.168.1.103:8080/lihuoming_23/3.png 当前手机和电脑 ...

  5. centos 6.5 dhcp桥接方式上网络设置

    首先虚拟机和主机之间采用桥接模式 然后在虚拟机中进行设置,首先进入到目录 /etc/sysconfig/network-scripts/ [root@localhost ~]# cd /etc/sys ...

  6. android面试详解

    前台就是和用户交互的进程 可见进程例如一个activity被一个透明的对话框覆盖,该activity就是可见进程 服务:service进程 后台一个activity按了home按键就是从前台退回到后台 ...

  7. 并发编程,python的进程,与线程

    并发编程 操作系统发展史 基于单核研究 多道技术 1.空间上的复用 多个程序公用一套计算机硬件 2.时间上的复用 切换+保存状态 例子:洗衣 烧水 做饭 切换 1.程序遇到IO操作系统会立刻剥夺走CP ...

  8. CLR垃圾收集器

    CLR GC是一种引用跟踪算法,大致步骤如下: 1.暂停进程中所有的线程: 2.标记阶段,遍历堆中的所有对象,标记为删除,然后检查所有活动根,如果有引用对象,就标记那个对象可达,否则不可达: 3.GC ...

  9. JsPlumb在react的使用方法及介绍

    JsPlumb在react的使用方法及介绍 一.相关资料来源: 1.https://bitqiang.gitbooks.io/jsplumb/content/Chapter1_IMPORTS_AND_ ...

  10. c# 线程的优先级

    前言 有时候我们希望某个线程更加重要,希望让其先运行的话.c#为我们提供了线程修改优先级.但是这样的效果有多大呢? 正文 直接放代码: static void Main(string[] args) ...