【韦德国际1946手机版】对象和数组,浅谈DataFr

作者: 韦德国际1946手机版  发布:2019-05-28

壹、DataFrame重回的不是指标。

通过 DataFrame[ ]方法,取得得都以行, [ ]【韦德国际1946手机版】对象和数组,浅谈DataFrame和斯ParkerSql取值误区。 中,加多过滤条件

不叨叨,直接来干货

本文暗中同意你早就有必然的python基础了。


import numpy as np

import pandas as pd

np_array  = np.array([[10,20,30],[30,40,45]])

pd_datas = pd.DataFrame(np_array,columns = ["iOS","android","window phone"])

print(pd_datas.iloc[0:2,0:3])


分片最难掌握的正是iloc了,当中用[x:x,x:x]来表示取值的限制,如下图所示

韦德国际1946手机版 1

上边1段程序的输出

内部第二个x:x是0:二,取的是行数,如图中评释的0和一,注意不包罗二。

第2个x:x是0:三,取的是列数,如何是iOS,android和window phone3列,也能够驾驭为0到叁列,不包蕴三。

浅谈json取值(对象和数组),浅谈json取值数组

按目的取值:

jQuery代码如下

(function ($) {
      $.getJSON('ajax/test.json', function (data) {
        var items = [];

        $.each(data.comments, function (key, val) {
          items.push('<li class="'   'tag'   val.class   '">'   '<a href="#">'   val.content   '</a>'   '</li>');
        });

        //第一个标签
        $('<ul/>', {
          'class':'',
          html:items.join('')
        }).appendTo('.tags');

        //第二个标签
        $('<ul/>', {
          'class':'alt',
          html:items.join('')
        }).appendTo('.tags');
      });
    })(jQuery);

json代码如下

{"comments":[
  {
    "class":"1",
    "content":"Lorem ipsum"
  },
  {
    "class":"2",
    "content":"Dolor sit amet"
  },
  {
    "class":"3",
    "content":"Consectetur adipiscing elit"
  },
  {
    "class":"2",
    "content":"Proin"
  },
  {
    "class":"4",
    "content":"Sagittis libero"
  },
  {
    "class":"1",
    "content":"Aliquet augue"
  },
  {
    "class":"1",
    "content":"Quisque dui lacus"
  },
  {
    "class":"5",
    "content":"Consequat"
  },
  {
    "class":"2",
    "content":"Dictum non"
  },
  {
    "class":"1",
    "content":"Venenatis et tortor"
  },
  {
    "class":"3",
    "content":"Suspendisse mauris"
  },
  {
    "class":"4",
    "content":"In accumsan"
  },
  {
    "class":"1",
    "content":"Egestas neque"
  },
  {
    "class":"5",
    "content":"Mauris eget felis"
  },
  {
    "class":"1",
    "content":"Suspendisse"
  },
  {
    "class":"2",
    "content":"condimentum eleifend nulla"
  }
]}

按数组取值:

jQuery代码如下

(function ($) {
      $.getJSON('ajax/test_array.json', function (data) {
        var items = [];

        $.each(data.comments, function (key, val) {
          items.push('<li class="'   'tag'   val[0]   '">'   '<a href="#">'   val[1]   '</a>'   '</li>');
        });

        //第一个标签
        $('<ul/>', {
          'class':'',
          html:items.join('')
        }).appendTo('.tags');

        //第二个标签
        $('<ul/>', {
          'class':'alt',
          html:items.join('')
        }).appendTo('.tags');
      });
    })(jQuery);

json代码如下

{"comments":[
  ["1", "Lorem ipsum"],
  ["2", "Dolor sit amet"],
  ["3", "Consectetur adipiscing elit"],
  ["2", "Proin"],
  ["4", "Sagittis libero"],
  ["1", "Aliquet augue"],
  ["1", "Quisque dui lacus"],
  ["5", "Consequat"],
  ["2", "Dictum non"],
  ["1", "Venenatis et tortor"],
  ["3", "Suspendisse mauris"],
  ["4", "In accumsan"],
  ["1", "Egestas neque"],
  ["5", "Mauris eget felis"],
  ["1", "Suspendisse"],
  ["2", "condimentum eleifend nulla"]
]}

共用的HTML代码如下

 <div class="tags"></div>

眼看能够观察按数组取值的数据量会小诸多

如上就是作者为我们带来的浅谈json取值(对象和数组)全体内容了,希望大家多多辅助帮客之家~

按指标取值: jQuery代码如下 (function ($) { $.getJSON('ajax/test.json', function (data) { var items = []; $.eac...

贰、DataFrame查出来的数据重返的是七个dataframe数据集。

data = pd.DataFrame(
    np.arange(16).reshape(4,4),
    index=['OP','CW','UZ','NM'],
    columns=['one','two','three','four']
)
# print data
     # one  two  three  four
# OP    0    1      2     3
# CW    4    5      6     7
# UZ    8    9     10    11
# NM   12   13     14    15
# print data['one']
# <class 'pandas.core.series.Series'>
#  x.shape  (4,)
# OP     0
# CW     4
# UZ     8
# NM    12
# Name: one, dtype: int64
# print type(data[['one','two']])
# <class 'pandas.core.frame.DataFrame'>
# x.shape (4,2)
    # one  two
# OP    0    1
# CW    4    5
# UZ    8    9
# NM   12   13

# print data[:2]
# <class 'pandas.core.frame.DataFrame'>
# .shape (2,4)
    # one  two  three  four
# OP    0    1      2     3
# CW    4    5      6     7

# print data>5
      # one    two  three   four
# OP  False  False  False  False
# CW  False  False   True   True
# UZ   True   True   True   True
# NM   True   True   True   True

# print data[data['three']>5]

# x.shape (3,4)
#     one  two  three  four
# CW    4    5      6     7
# UZ    8    9     10    11
# NM   12   13     14    15

# print data[data>5]
#      one   two  three  four
# OP   NaN   NaN    NaN   NaN
# CW   NaN   NaN    6.0   7.0
# UZ   8.0   9.0   10.0  11.0
# NM  12.0  13.0   14.0  15.0

# data[data<5] = 0
# print data
    # one  two  three  four
# OP    0    0      0     0
# CW    0    5      6     7
# UZ    8    9     10    11
# NM   12   13     14    15

print data[2] # 报错。
print data.ix[2] #  √

叁、DataFrame唯有遇见Action的算子本事进行

四、斯ParkerSql查出来的多寡再次回到的是二个dataframe数据集。

本来数据

scala> val parquetDF = sqlContext.read.parquet("hdfs://hadoop14:9000/yuhui/parquet/part-r-00004.gz.parquet")
df: org.apache.spark.sql.DataFrame = [timestamp: string, appkey: string, app_version: string, channel: string, lang: string, os_type: string, os_version: string, display: string, device_type: string, mac: string, network: string, nettype: string, suuid: string, register_days: int, country: string, area: string, province: string, city: string, event: string, use_interval_cat: string, use_duration_cat: string, use_interval: bigint, use_duration: bigint, os_upgrade_from: string, app_upgrade_from: string, page_name: string, event_name: string, error_type: string]

本文由韦德国际1946发布于韦德国际1946手机版,转载请注明出处:【韦德国际1946手机版】对象和数组,浅谈DataFr

关键词: pandas 日记本 伟德娱乐