精华内容
参与话题
问答
  • Series

    2017-03-27 01:00:11
    An arithmetic series consists of a sequence of terms such that each term minus its immediate predecessor gives the same result. For example, the sequence 3, 7, 11, 15 is the terms of the arithmetic ...
  • Pandas Series转换为DataFrame

    万次阅读 多人点赞 2018-10-08 13:43:55
    虽然Series有一个to_frame()方法,但是当Series的index也需要转变为DataFrame的一列时,这个方法转换会有一点问题。所以,下面我采用将Series对象转换为list对象,然后将list对象转换为DataFrame对象。 实例 这里的...

    详细可以见我的个人博客:Pandas Series转换为DataFrame

    说明

    虽然Series有一个to_frame()方法,但是当Series的index也需要转变为DataFrame的一列时,这个方法转换会有一点问题。所以,下面我采用将Series对象转换为list对象,然后将list对象转换为DataFrame对象。

    实例

    这里的month为一个series对象:

    type(month)
    pandas.core.series.Series
    

    它的index为月份,values为数量,下面将这两列都转换为DataFrame的columns。

    import pandas as pd
    
    dict_month = {'month':month.index,'numbers':month.values}
    df_month = pd.DataFrame(dict_month)
    
    展开全文
  • pandas.core.series.Series

    2020-10-12 10:00:02
    1 Series 线性的数据结构, series是一个一维数组 Pandas 会默然用0到n-1来作为series的index, 但也可以自己指定index( 可以把index理解为dict里面的key ) 1.1创造一个serise数据 import pandas as pd import ...

    1 Series

    线性的数据结构, series是一个一维数组

    Pandas 会默然用0到n-1来作为series的index, 但也可以自己指定index( 可以把index理解为dict里面的key )

    1.1创造一个serise数据

    import pandas as pd
    import numpy as np
    ​
    s = pd.Series([9, 'zheng', 'beijing', 128])
    ​
    print(s)
    • 打印

    打印
    
    0          9
    1      zheng
    2    beijing
    3        128
    dtype: object
    • 访问其中某个数据

    访问其中某个数据
    
    print(s[1:2])
    ​
    # 打印
    1    zheng
    dtype: object

    1.2 指定index

    import pandas as pd
    import numpy as np
    ​
    s = pd.Series([9, 'zheng', 'beijing', 128, 'usa', 990], index=[1,2,3,'e','f','g'])
    ​
    print(s)
    • 打印

    打印
    
    1          9
    2      zheng
    3    beijing
    e        128
    f        usa
    g        990
    dtype: object
    • 根据索引找出值

    print(s['f'])    # usa

    1.3 用dictionary构造一个series

    import pandas as pd
    import numpy as np
    ​
    s = {"ton": 20, "mary": 18, "jack": 19, "car": None}
    ​
    sa = pd.Series(s, name="age")
    ​
    print(sa)
    • 打印

    car      NaN
    jack    19.0
    mary    18.0
    ton     20.0
    Name: age, dtype: float64
    • 检测类型

    print(type(sa))    # <class 'pandas.core.series.Series'>

    1.4 用numpy ndarray构造一个Series

    #生成一个随机数

    import pandas as pd
    import numpy as np
    ​
    num_abc = pd.Series(np.random.randn(5), index=list('abcde'))
    num = pd.Series(np.random.randn(5))
    ​
    print(num)
    print(num_abc)
    ​
    # 打印
    0   -0.102860
    1   -1.138242
    2    1.408063
    3   -0.893559
    4    1.378845
    dtype: float64
    a   -0.658398
    b    1.568236
    c    0.535451
    d    0.103117
    e   -1.556231
    dtype: float64

    1.5 选择数据

    import pandas as pd
    import numpy as np
    ​
    s = pd.Series([9, 'zheng', 'beijing', 128, 'usa', 990], index=[1,2,3,'e','f','g'])
    ​
    print(s[1:3])  # 选择第1到3个, 包左不包右 zheng beijing
    print(s[[1,3]])  # 选择第1个和第3个, zheng 128
    print(s[:-1]) # 选择第1个到倒数第1个, 9 zheng beijing 128 usa

    1.6 操作数据

    import pandas as pd
    import numpy as np
    ​
    s = pd.Series([9, 'zheng', 'beijing', 128, 'usa', 990], index=[1,2,3,'e','f','g'])
    ​
    sum = s[1:3] + s[1:3]
    sum1 = s[1:4] + s[1:4]
    sum2 = s[1:3] + s[1:4]
    sum3 = s[:3] + s[1:]
    ​
    print(sum)
    print(sum1)
    print(sum2)
    print(sum3)

    #打印

    2        zhengzheng
    3    beijingbeijing
    dtype: object
    2        zhengzheng
    3    beijingbeijing
    e               256
    dtype: object
    2        zhengzheng
    3    beijingbeijing
    e               NaN
    dtype: object
    1               NaN
    2        zhengzheng
    3    beijingbeijing
    e               NaN
    f               NaN
    g               NaN
    dtype: object

    1.7 查找

    • 范围查找
      import pandas as pd
      import numpy as np
       
      s = {"ton": 20, "mary": 18, "jack": 19, "jim": 22, "lj": 24, "car": None}
       
      sa = pd.Series(s, name="age")
       
      print(sa[sa>19])
      

    • 中位数
      import pandas as pd
      import numpy as np
       
      s = {"ton": 20, "mary": 18, "jack": 19, "jim": 22, "lj": 24, "car": None}
       
      sa = pd.Series(s, name="age")
       
      print(sa.median())  # 20
      

       

    • 判断是否大于中位数
      import pandas as pd
      import numpy as np
       
      s = {"ton": 20, "mary": 18, "jack": 19, "jim": 22, "lj": 24, "car": None}
       
      sa = pd.Series(s, name="age")
       
      print(sa>sa.median())
      

    • 1.9 满足条件的统一赋值

      import pandas as pd
      import numpy as np
       
      s = {"ton": 20, "mary": 18, "jack": 19, "jim": 22, "lj": 24, "car": None}
       
      sa = pd.Series(s, name="age")
       
      print(s) # 打印原字典
       
      print('---------------------')   # 分割线
       
      sa[sa>19] = 88 # 将所有大于19的同一改为88
       
      print(sa) # 打印更改之后的数据
       
      print('---------------------')   # 分割线
       
      print(sa / 2) # 将所有数据除以2
      

    展开全文
  • demo.py(Series取值,切片): import pandas as pd t1 = pd.Series([13, 23, 33, 43, 53], index=["a", "b", "c", "d", "e"]) print(t1) ''' a 13 b 23 c ...

     

    demo.py(Series取值,切片):

    import pandas as pd
    
    
    t1 = pd.Series([13, 23, 33, 43, 53], index=["a", "b", "c", "d", "e"])
    print(t1)
    '''
    a    13
    b    23
    c    33
    d    43
    e    53
    dtype: int64
    '''
    
    # 通过索引直接取值
    print(t1["d"])  # 43
    # 通过位置取值(从0开始)
    print(t1[3])  # 43
    
    
    # 切片
    # 取位置连续的值
    print(t1[1:4])  # 也可以指定步长
    '''
    b    23
    c    33
    d    43
    dtype: int64
    '''
    
    # 取位置不连续的值
    print(t1[[1,3]])
    '''
    b    23
    d    43
    dtype: int64
    '''
    # 也可以通过索引取多个值
    print(t1[["b","d","w"]])  # 如果指定的索引不存在,那么对应值就返回NaN(float类型)
    '''
    b    23.0
    d    43.0
    w     NaN
    dtype: float64
    '''
    

    demo.py(Series的index和values属性):

    import pandas as pd
    
    
    t1 = pd.Series([13, 23, 33, 43, 53], index=["a", "b", "c", "d", "e"])
    print(t1)
    '''
    a    13
    b    23
    c    33
    d    43
    e    53
    dtype: int64
    '''
    
    print(type(t1.index))  # <class 'pandas.core.indexes.base.Index'>
    print(t1.index)   # Index(['a', 'b', 'c', 'd', 'e'], dtype='object')
    print(len(t1.index))  # 5  有长度 可以遍历迭代
    # 可以强制转换成list类型
    print(list(t1.index))  # ['a', 'b', 'c', 'd', 'e']
    
    
    print(type(t1.values))  # <class 'numpy.ndarray'>
    print(t1.values)   # [13 23 33 43 53]
    # ndarray的很多方法都可以运用到Series类型。 例如:argmax()获取最大值;clip()裁剪等。
    
    # Series对象本质上由两个数组构成,一个构成索引index,一个构成对象的值values
    
    

    demo.py(Series的布尔索引):

    import pandas as pd
    
    
    t1 = pd.Series([13, 23, 33, 43, 53], index=["a", "b", "c", "d", "e"])
    print(t1)
    '''
    a    13
    b    23
    c    33
    d    43
    e    53
    dtype: int64
    '''
    
    # Series类型也支持bool索引。
    print(t1[t1>30])
    '''
    c    33
    d    43
    e    53
    dtype: int64
    '''
    
    t1[t1>30] = 0
    print(t1)
    '''
    a    13
    b    23
    c     0
    d     0
    e     0
    dtype: int64
    '''
    

     

     

    展开全文
  • Pandas Series

    千次阅读 2017-05-24 13:17:18
    构造方法 方法 描述 Series([data, index, dtype, name, copy, …]) 一维序列 属性 方法 描述 Series.index 轴标签 Series.values ...

    http://pandas-docs.github.io/pandas-docs-travis/api.html

    构造方法

    方法 描述
    Series([data, index, dtype, name, copy, …]) 一维序列

    属性

    方法 描述
    Series.index 轴标签
    Series.values 返回序列的数值
    Series.dtype 返回数据的类型
    Series.ftype return if the data is sparse
    Series.shape 返回数据的型状
    Series.nbytes 返回数据的字节数
    Series.ndim 返回数据的维度
    Series.size 返回元素的个数
    Series.strides return the strides of the underlying data
    Series.itemsize return the size of the dtype of the item of the underlying data
    Series.base return the base object if the memory of the underlying data is
    Series.T 返回转置
    Series.memory_usage([index, deep]) Memory usage of the Series

    转换

    方法 描述
    Series.astype(dtype[, copy, raise_on_error]) Cast object to input numpy.dtype
    Series.copy([deep]) 复制Series
    Series.isnull() 测定是null,返回布尔值
    Series.notnull() 测定不是null,返回布尔值

    索引和迭代

    方法 描述
    Series.get(key[, default]) 返回所要得到的值
    Series.at 快速的标量访问器,使用标签
    Series.iat 快速的标量访问器,使用整型
    Series.ix 只能快速访问器,先使用标签,再使用整型
    Series.loc 标签索引
    Series.iloc 整型索引
    Series.iter() 序列值迭代器
    Series.iteritems() 惰性迭代器,返回索引和值

    二元运算

    方法 描述
    Series.add(other[, level, fill_value, axis]) 加法,元素指向
    Series.sub(other[, level, fill_value, axis]) 减法,元素指向
    Series.mul(other[, level, fill_value, axis]) 乘法,元素指向
    Series.div(other[, level, fill_value, axis]) 除法,元素指向,结果为浮点
    Series.truediv(other[, level, fill_value, axis]) 真除法,元素指向
    Series.floordiv(other[, level, fill_value, axis]) 向下取整除法,元素指向
    Series.mod(other[, level, fill_value, axis]) 模运算,元素指向
    Series.pow(other[, level, fill_value, axis]) 幂运算,元素指向
    Series.radd(other[, level, fill_value, axis]) 右侧加法,元素指向
    Series.rsub(other[, level, fill_value, axis]) 右侧减法,元素指向
    Series.rmul(other[, level, fill_value, axis]) 右侧乘法,元素指向
    Series.rdiv(other[, level, fill_value, axis]) 右侧除法,元素指向
    Series.rtruediv(other[, level, fill_value, axis]) 真右侧除法,元素指向
    Series.rfloordiv(other[, level, fill_value, …]) 向下取整右侧除法,元素指向
    Series.rmod(other[, level, fill_value, axis]) 右侧模运算,元素指向
    Series.rpow(other[, level, fill_value, axis]) 右侧幂运算,元素指向
    Series.combine(other, func[, fill_value]) Perform elementwise binary operation on two Series using given function
    Series.combine_first(other) Combine Series values, choosing the calling Series’s values first.
    Series.round([decimals]) 随机抽取序列的值
    Series.lt(other[, level, fill_value, axis]) 小于另一个序列,元素指向
    Series.gt(other[, level, fill_value, axis]) 大于另一个序列,元素指向
    Series.le(other[, level, fill_value, axis]) 小于等于另一个序列,元素指向
    Series.ge(other[, level, fill_value, axis]) 大于等于另一个序列,元素指向
    Series.ne(other[, level, fill_value, axis]) 不等于另一个序列,元素指向
    Series.eq(other[, level, fill_value, axis]) 等于另一个序列,元素指向

    函数应用&分组&窗口

    方法 描述
    Series.apply(func[, convert_dtype, args]) Invoke function on values of Series.
    Series.map(arg[, na_action]) Map values of Series using input correspondence (which can be
    Series.groupby([by, axis, level, as_index, …]) 分组
    Series.rolling(window[, min_periods, freq, …]) 移动窗口
    Series.expanding([min_periods, freq, …]) 扩展窗口
    Series.ewm([com, span, halflife, alpha, …]) 指数权重窗口

    描述统计学

    方法 描述
    Series.abs() 绝对值
    Series.all([axis, bool_only, skipna, level]) Return whether all elements are True over requested axis
    Series.any([axis, bool_only, skipna, level]) Return whether any element is True over requested axis
    Series.autocorr([lag]) Lag-N autocorrelation
    Series.between(left, right[, inclusive]) Return boolean Series equivalent to left <= series <= right.
    Series.clip([lower, upper, axis]) Trim values at input threshold(s).
    Series.clip_lower(threshold[, axis]) Return copy of the input with values below given value(s) truncated.
    Series.clip_upper(threshold[, axis]) Return copy of input with values above given value(s) truncated.
    Series.corr(other[, method, min_periods]) 相关性
    Series.count([level]) 返回序列数据个数
    Series.cov(other[, min_periods]) 协方差
    Series.cummax([axis, skipna]) Return cumulative max over requested axis.
    Series.cummin([axis, skipna]) Return cumulative minimum over requested axis.
    Series.cumprod([axis, skipna]) 累乘
    Series.cumsum([axis, skipna]) 累加
    Series.describe([percentiles, include, exclude]) 描述
    Series.diff([periods]) 1st discrete difference of object
    Series.factorize([sort, na_sentinel]) Encode the object as an enumerated type or categorical variable
    Series.kurt([axis, skipna, level, numeric_only]) 峰度
    Series.mad([axis, skipna, level]) 局对平均偏差
    Series.max([axis, skipna, level, numeric_only]) 最大值
    Series.mean([axis, skipna, level, numeric_only]) 平均值
    Series.median([axis, skipna, level, …]) 中位数
    Series.min([axis, skipna, level, numeric_only]) 最小值
    Series.mode() Returns the mode(s) of the dataset.
    Series.nlargest(*args, **kwargs) Return the largest n elements.
    Series.nsmallest(*args, **kwargs) Return the smallest n elements.
    Series.pct_change([periods, fill_method, …]) 增长率
    Series.prod([axis, skipna, level, numeric_only]) 乘积
    Series.quantile([q, interpolation]) 分位数
    Series.rank([axis, method, numeric_only, …]) 排名
    Series.sem([axis, skipna, level, ddof, …]) Return unbiased standard error of the mean over requested axis.
    Series.skew([axis, skipna, level, numeric_only]) 偏度
    Series.std([axis, skipna, level, ddof, …]) 标准差
    Series.sum([axis, skipna, level, numeric_only]) 求和
    Series.var([axis, skipna, level, ddof, …]) 方差
    Series.unique() 返回唯一值
    Series.nunique([dropna]) R返回唯一值的个数
    Series.is_unique 是否为唯一值
    Series.is_monotonic Return boolean if values in the object are
    Series.is_monotonic_increasing Return boolean if values in the object are
    Series.is_monotonic_decreasing Return boolean if values in the object are
    Series.value_counts([normalize, sort, …]) 唯一值计数

    从新索引&选择&标签操控

    方法 描述
    Series.align(other[, join, axis, level, …]) Align two object on their axes with the
    Series.drop(labels[, axis, level, inplace, …]) 返回移除的数据
    Series.drop_duplicates(*args, **kwargs) Return Series with duplicate values removed
    Series.duplicated(*args, **kwargs) Return boolean Series denoting duplicate values
    Series.equals(other) 是否含有相同的元素
    Series.first(offset) Convenience method for subsetting initial periods of time series data based on a date offset.
    Series.head([n]) 返回前n行
    Series.idxmax([axis, skipna]) Index of first occurrence of maximum of values.
    Series.idxmin([axis, skipna]) 返回最小值的索引
    Series.isin(values) 是否包含序列的元素
    Series.last(offset) Convenience method for subsetting final periods of time series data based on a date offset.
    Series.reindex([index]) Conform Series to new index with optional filling logic, placing NA/NaN in locations having no value in the previous index.
    Series.reindex_like(other[, method, copy, …]) Return an object with matching indices to myself.
    Series.rename([index]) Alter axes input function or functions.
    Series.rename_axis(mapper[, axis, copy, inplace]) Alter index and / or columns using input function or functions.
    Series.reset_index([level, drop, name, inplace]) Analogous to the pandas.DataFrame.reset_index() function, see docstring there.
    Series.sample([n, frac, replace, weights, …]) 随机抽样
    Series.select(crit[, axis]) Return data corresponding to axis labels matching criteria
    Series.take(indices[, axis, convert, is_copy]) return Series corresponding to requested indices
    Series.tail([n]) 返回最后几行
    Series.truncate([before, after, axis, copy]) Truncates a sorted NDFrame before and/or after some particular index value.
    Series.where(cond[, other, inplace, axis, …]) 条件选择
    Series.mask(cond[, other, inplace, axis, …]) Return an object of same shape as self and whose corresponding entries are from self where cond is False and otherwise are from other.

    处理缺失值

    方法 描述
    Series.dropna([axis, inplace]) 返回没有缺失值的序列
    Series.fillna([value, method, axis, …]) 填充缺失值
    Series.interpolate([method, axis, limit, …]) Interpolate values according to different methods.

    重塑&排序

    方法 描述
    Series.argsort([axis, kind, order]) Overrides ndarray.argsort.
    Series.reorder_levels(order) Rearrange index levels using input order.
    Series.sort_values([axis, ascending, …]) Sort by the values along either axis
    Series.sort_index([axis, level, ascending, …]) Sort object by labels (along an axis)
    Series.sortlevel([level, ascending, …]) Sort Series with MultiIndex by chosen level.
    Series.swaplevel([i, j, copy]) Swap levels i and j in a MultiIndex
    Series.unstack([level, fill_value]) Unstack, a.k.a.
    Series.searchsorted(v[, side, sorter]) Find indices where elements should be inserted to maintain order.

    Combining&joining&merging

    方法 描述
    Series.append(to_append[, ignore_index, …]) Concatenate two or more Series.
    Series.replace([to_replace, value, inplace, …]) Replace values given in ‘to_replace’ with ‘value’.
    Series.update(other) Modify Series in place using non-NA values from passed Series.

    时间序列相关

    方法 描述
    Series.asfreq(freq[, method, how, normalize]) 将时间序列转换为特定的频率
    Series.asof(where[, subset]) The last row without any NaN is taken (or the last row without
    Series.shift([periods, freq, axis]) Shift index by desired number of periods with an optional time freq
    Series.first_valid_index() Return label for first non-NA/null value
    Series.last_valid_index() Return label for last non-NA/null value
    Series.resample(rule[, how, axis, …]) Convenience method for frequency conversion and resampling of time series.
    Series.tz_convert(tz[, axis, level, copy]) Convert tz-aware axis to target time zone.
    Series.tz_localize(*args, **kwargs) Localize tz-naive TimeSeries to target time zone.

    类似Datetime类型的属性

    DateTime属性

    方法 描述
    Series.dt.date Returns numpy array of python datetime.date objects (namely, the date part of Timestamps without timezone information).
    Series.dt.time Returns numpy array of datetime.time.
    Series.dt.year 返回年份
    Series.dt.month 返回月份
    Series.dt.day 返回天
    Series.dt.hour 返回小时
    Series.dt.minute 返回分钟
    Series.dt.second 返回秒
    Series.dt.microsecond 返回微秒
    Series.dt.nanosecond 返回纳秒
    Series.dt.week 返回周在年份中的名次
    Series.dt.weekofyear 返回周在年份中的名次
    Series.dt.dayofweek 返回日在周中的名次 Monday=0, Sunday=6
    Series.dt.weekday 返回日在周中的名次Monday=0, Sunday=6
    Series.dt.weekday_name 返回周中日的名字 (ex: Friday)
    Series.dt.dayofyear 返回日在年中的名次
    Series.dt.quarter 季度
    Series.dt.is_month_start 是否是月份的第一天
    Series.dt.is_month_end 是否是月份的最后一天
    Series.dt.is_quarter_start 是否是季度的第一天
    Series.dt.is_quarter_end 是否是季度的最后一天
    Series.dt.is_year_start 是否是年的第一天
    Series.dt.is_year_end 是否是年的最后一天
    Series.dt.is_leap_year Logical indicating if the date belongs to a leap year
    Series.dt.daysinmonth 月份一共有多少天
    Series.dt.days_in_month 月份一共有多少天
    Series.dt.freq get/set the frequncy of the Index

    DateTime方法

    方法 描述
    Series.dt.to_period(*args, **kwargs) Cast to PeriodIndex at a particular frequency
    Series.dt.to_pydatetime()
    Series.dt.tz_localize(*args, **kwargs) Localize tz-naive DatetimeIndex to given time zone (using
    Series.dt.tz_convert(*args, **kwargs) Convert tz-aware DatetimeIndex from one time zone to another (using
    Series.dt.normalize(*args, **kwargs) Return DatetimeIndex with times to midnight.
    Series.dt.strftime(*args, **kwargs) Return an array of formatted strings specified by date_format, which supports the same string format as the python standard library.
    Series.dt.round(*args, **kwargs) round the index to the specified freq
    Series.dt.floor(*args, **kwargs) floor the index to the specified freq
    Series.dt.ceil(*args, **kwargs) ceil the index to the specified freq

    Timedelta属性

    方法 描述
    Series.dt.days Number of days for each element.
    Series.dt.seconds Number of seconds (>= 0 and less than 1 day) for each element.
    Series.dt.microseconds Number of microseconds (>= 0 and less than 1 second) for each element.
    Series.dt.nanoseconds Number of nanoseconds (>= 0 and less than 1 microsecond) for each element.
    Series.dt.components Return a dataframe of the components (days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds) of the Timedeltas.

    Timedelta方法

    方法 描述
    Series.dt.to_pytimedelta()
    Series.dt.total_seconds(*args, **kwargs) Total duration of each element expressed in seconds.

    字符串处理

    方法 描述
    Series.str.capitalize() 首字母大写
    Series.str.cat([others, sep, na_rep]) 连接字符串
    Series.str.center(width[, fillchar]) Filling left and right side of strings in the Series/Index with an additional character.
    Series.str.contains(pat[, case, flags, na, …]) 是否包含
    Series.str.count(pat[, flags]) Count occurrences of pattern in each string of the Series/Index.
    Series.str.decode(encoding[, errors]) Decode character string in the Series/Index using indicated encoding.
    Series.str.encode(encoding[, errors]) Encode character string in the Series/Index using indicated encoding.
    Series.str.endswith(pat[, na]) 是否以…结尾
    Series.str.extract(pat[, flags, expand]) For each subject string in the Series, extract groups from the first match of regular expression pat.
    Series.str.extractall(pat[, flags]) For each subject string in the Series, extract groups from all matches of regular expression pat.
    Series.str.find(sub[, start, end]) Return lowest indexes in each strings in the Series/Index where the substring is fully contained between [start:end].
    Series.str.findall(pat[, flags]) Find all occurrences of pattern or regular expression in the Series/Index.
    Series.str.get(i) Extract element from lists, tuples, or strings in each element in the Series/Index.
    Series.str.index(sub[, start, end]) Return lowest indexes in each strings where the substring is fully contained between [start:end].
    Series.str.join(sep) Join lists contained as elements in the Series/Index with passed delimiter.
    Series.str.len() 计算所有的长度
    Series.str.ljust(width[, fillchar]) Filling right side of strings in the Series/Index with an additional character.
    Series.str.lower() 小写
    Series.str.lstrip([to_strip]) Strip whitespace (including newlines) from each string in the Series/Index from left side.
    Series.str.normalize(form) Return the Unicode normal form for the strings in the Series/Index.
    Series.str.pad(width[, side, fillchar]) Pad strings in the Series/Index with an additional character to specified side.
    Series.str.partition([pat, expand]) Split the string at the first occurrence of sep, and return 3 elements containing the part before the separator, the separator itself, and the part after the separator.
    Series.str.repeat(repeats) Duplicate each string in the Series/Index by indicated number of times.
    Series.str.replace(pat, repl[, n, case, flags]) 替换
    Series.str.rfind(sub[, start, end]) Return highest indexes in each strings in the Series/Index where the substring is fully contained between [start:end].
    Series.str.rindex(sub[, start, end]) Return highest indexes in each strings where the substring is fully contained between [start:end].
    Series.str.rjust(width[, fillchar]) Filling left side of strings in the Series/Index with an additional character.
    Series.str.rpartition([pat, expand]) Split the string at the last occurrence of sep, and return 3 elements containing the part before the separator, the separator itself, and the part after the separator.
    Series.str.rstrip([to_strip]) Strip whitespace (including newlines) from each string in the Series/Index from right side.
    Series.str.slice([start, stop, step]) Slice substrings from each element in the Series/Index
    Series.str.slice_replace([start, stop, repl]) Replace a slice of each string in the Series/Index with another string.
    Series.str.split([pat, n, expand]) 分割字符串
    Series.str.rsplit([pat, n, expand]) 从右边分割字符串
    Series.str.startswith(pat[, na]) 是否以…开头
    Series.str.strip([to_strip]) 去两边的空白
    Series.str.swapcase() 大小写翻转
    Series.str.title() 首字母大写
    Series.str.translate(table[, deletechars]) 根据映射表翻译
    Series.str.upper() 全部大写
    Series.str.wrap(width, **kwargs) Wrap long strings in the Series/Index to be formatted in paragraphs with length less than a given width.
    Series.str.zfill(width) Filling left side of strings in the Series/Index with 0.
    Series.str.isalnum() 是否是个数字
    Series.str.isalpha() 是否是个字母
    Series.str.isdigit() Check whether all characters in each string in the Series/Index are digits.
    Series.str.isspace() 是否是空白
    Series.str.islower() 是否是小写
    Series.str.isupper() 是否是大学
    Series.str.istitle() 首字母大写
    Series.str.isnumeric() 数字
    Series.str.isdecimal() 小数
    Series.str.get_dummies([sep]) Split each string in the Series by sep and return a frame of dummy/indicator variables.

    分类

    方法 描述
    Series.cat.categories The categories of this categorical.
    Series.cat.ordered Gets the ordered attribute
    Series.cat.codes
    Series.cat.rename_categories(*args, **kwargs) Renames categories.
    Series.cat.reorder_categories(*args, **kwargs) Reorders categories as specified in new_categories.
    Series.cat.add_categories(*args, **kwargs) Add new categories.
    Series.cat.remove_categories(*args, **kwargs) Removes the specified categories.
    Series.cat.remove_unused_categories(*args, …) Removes categories which are not used.
    Series.cat.set_categories(*args, **kwargs) Sets the categories to the specified new_categories.
    Series.cat.as_ordered(*args, **kwargs) Sets the Categorical to be ordered
    Series.cat.as_unordered(*args, **kwargs) Sets the Categorical to be unordered
    Categorical(values[, categories, ordered, …]) Represents a categorical variable in classic R / S-plus fashion
    Categorical.from_codes(codes, categories[, …]) Make a Categorical type from codes and categories arrays.

    作图

    方法 描述
    Series.plot([kind, ax, figsize, ….]) Series plotting accessor and method
    Series.plot.area(**kwds) 面积图Area plot
    Series.plot.bar(**kwds) 垂直条形图Vertical bar plot
    Series.plot.barh(**kwds) 水平条形图Horizontal bar plot
    Series.plot.box(**kwds) 箱图Boxplot
    Series.plot.density(**kwds) 核密度Kernel Density Estimate plot
    Series.plot.hist([bins]) 直方图Histogram
    Series.plot.kde(**kwds) 核密度Kernel Density Estimate plot
    Series.plot.line(**kwds) 线图Line plot
    Series.plot.pie(**kwds) 饼图Pie chart
    Series.hist([by, ax, grid, xlabelsize, …]) Draw histogram of the input series using matplotlib

    转化为其他格式

    方法 描述
    Series.from_csv(path[, sep, parse_dates, …]) Read CSV file (DEPRECATED, please use pandas.read_csv()instead).
    Series.to_pickle(path[, compression, protocol]) Pickle (serialize) object to input file path.
    Series.to_csv([path, index, sep, na_rep, …]) Write Series to a comma-separated values (csv) file
    Series.to_dict([into]) Convert Series to {label -> value} dict or dict-like object.
    Series.to_excel(excel_writer[, sheet_name, …]) Write Series to an excel sheet
    Series.to_frame([name]) Convert Series to DataFrame
    Series.to_xarray() Return an xarray object from the pandas object.
    Series.to_hdf(path_or_buf, key, **kwargs) Write the contained data to an HDF5 file using HDFStore.
    Series.to_sql(name, con[, flavor, schema, …]) Write records stored in a DataFrame to a SQL database.
    Series.to_msgpack([path_or_buf, encoding]) msgpack (serialize) object to input file path
    Series.to_json([path_or_buf, orient, …]) Convert the object to a JSON string.
    Series.to_sparse([kind, fill_value]) Convert Series to SparseSeries
    Series.to_dense() Return dense representation of NDFrame (as opposed to sparse)
    Series.to_string([buf, na_rep, …]) Render a string representation of the Series
    Series.to_clipboard([excel, sep]) Attempt to write text representation of object to the system clipboard This can be pasted into Excel, for example.
    Series.to_latex([buf, columns, col_space, …]) Render an object to a tabular environment table.
    展开全文
  • series是pandas的一种数据类型,Series是一个定长的,有序的字典,因为它把索引和值映射起来了。通过以下例子,可以更加清楚它们的数据表示。1、list to others# list data = [[2000, 'Ohino', 1.5],
  • Series.rename 如何对Series重取列名

    千次阅读 2020-06-19 20:08:10
    Series.rename 如何对Series重取列名 想要把图中的Series红框中的列名更改了,怎么办? a.rename('rank',inplace=True) 变成下面:
  • DeepID Series Deep Learning Face Representation from Predicting 10,000 Classes [Yi Sun et al., 2014] Deep Learning Face Representation by Joint Identification-Verification [Yi Sun et al., 2014] ...
  • pandas中Series,DataFrame的连接(拼接)

    万次阅读 多人点赞 2017-05-13 01:15:34
    上一篇中介绍了numpy中数组的拼接方式:numpy中数组的拼接 ,接下来介绍另一个数据处理库pandas中最常用的Series和DataFrame对序列和表格的操作 concat 如numpy中数组的拼接 中所讲是numpy中concatenate的...
  • Fourier Series A Fourier series is an expansion of a periodic function in terms of an infinite sum of sines and cosines. Fourier series make use of the orthogonality relationships of
  • Pandas把dataframe或series转换成list

    万次阅读 多人点赞 2019-08-12 12:25:15
    把dataframe转换为list 输入多维dataframe: df = pd.DataFrame({'a':[1,3,5,7,4,5,6,4,7,8,9], 'b':[3,5,6,2,4,6,7,8,7,8,9]}) 把a列的元素转换成list: ...df['a'].values.tolist() ...把a列中不重复的元素转...
  • Pandas Series核心点总结

    万次阅读 多人点赞 2020-10-13 16:07:55
    Pandas数据结构Series2.1 构造和初始化Series2.2 Series的基本属性2.3 选择数据2.4 赋值运算2.5 数学运算 1. Pandas简介 Python数据分析的核心库之一 基于Numpy (对ndarray的操作) 更能体会到Python的Functional ...
  • Series和DataFrame的排序

    千次阅读 2020-08-08 22:08:38
    Series和DataFrame的排序Series和DataFrame的排序引入相关库Series的排序DataFrame的排序 Series和DataFrame的排序 引入相关库 import numpy as np import pandas as pd from pandas import Series,DataFrame ...
  • Python之Pandas中Series、DataFrame实践

    万次阅读 2016-01-06 16:00:33
    Python之Pandas中Series、DataFrame实践1. pandas的数据结构Series1.1 Series是一种类似于一维数组的对象,它由一组数据(各种NumPy数据类型)以及一组与之相关的数据标签(即索引)组成。 1.2 Series的字符串表现...
  • echarts动态series

    千次阅读 2019-10-31 10:19:31
    /动态series/ var series=[]; for(var i in newData) { series.push({ name: newData[i].name, type: 'line', xAxisIndex: i, ...
  • Generalized Fourier Series A generalized Fourier series is a series expansion of a function based on the special properties of a complete orthogonal system of functions. The prototypical examp
  • python 创建Series

    千次阅读 2019-09-22 22:05:02
    #创建Series #用于存储一行或一列的数据,以及与之相关的索引的集合 import pandas as pd s1 = pd.Series([43,56]) print(s1) s2 = pd.Series([43,12.4]) print(s2) s3 = pd.Series([False,True]) print(s3) #有...
  • echarts的series配置

    万次阅读 2019-02-19 11:09:33
    series: [ { name: name0, type: type0, smooth: false, yAxisIndex: 0, data: xdata, itemStyle: { normal: { color:'#1890FF', label: { color:'#00...
  • pd.Series()函数

    万次阅读 多人点赞 2019-10-18 20:40:39
    1.Series介绍 S Pandas模块的数据结构主要有两种:1.Series 2.DataFrame Series 是一维数组,基于Numpy的ndarray 结构 Series([data, index, dtype, name, copy, …]) # One-dimensional ndarray with axis labels ...
  • pandas - Series

    千次阅读 2018-06-27 15:11:05
    Series 创建时需要data/index两个信息 Series可以通过array/dict/scalar创建 Series可以看作dict/ndarray,和numpy互通 Series计算时自动按标签对齐 源 Series是带标签的一维数组,支持任意数据类型(整型,字符传,...
  • Pandas 安装: pip install pandas numpy 和pandas 区别: ...series: 一维数组类似array,series=索引+数据。区别是Series能保存不同种数据类型,字符串、boolean值、数字等,而numpy只能存储同类型数...
  • http://mathworld.wolfram.com/LaplaceSeries.html Laplace Series The spherical harmonics form a complete orthogonal system, so an arbitrary real function can be expanded in terms of com
  • Series(二):Series的元素获取方式

    千次阅读 2020-03-18 09:05:00
    ↑关注 + 星标~有趣的不像个技术号每晚九点,我们准时相约大家好,我是黄同学今天给大家介绍Series的元素获取方式。关于切片和索引获取Ser...
  • pandas创建Series

    2019-05-22 14:23:49
    如何创建Series对象 常见的创建Pandas对象的方式,都像这样的形式: pd.Series(data, index=index)1 其中,index是一个可选参数...
  • Series和DataFrame

    2018-08-22 14:26:10
    Series和DataFrame都是Pandas中的数据类型 Series可以认为是一维数组 DataFrame可以认为是二维数组 &amp;gt;&amp;gt;&amp;gt; from pandas import Series,DataFrame &amp;gt;&amp;gt;&...
  • Pandas Series操作

    2017-04-28 10:20:38
    1. map操作series.map(func)>>> import pandas as pd >>> series = pd.Series([1, 2, 3]) >>> series 0 1 1 2 2 3 dtype: int64 >>> series.map(lambda x: x*10) 0 10 1 20 2 30 dtype: int64
  • series转换成dataframe

    千次阅读 2019-03-14 16:28:18
    在平时数据分析时,通过describe和groupby生成的统计数据,更多的时候是属于series格式的。 而我们在后续的分析或者数据合并的过程中,我们往往需要将series格式转换成dataframe格式,往往存在以下两种情况 单个的...
  • 序列:Series 用于存储一行或者一列的数据,以及与之相关的索引集合(类似于列表,但是有索引) 数据定义: #序列的导入 from pandas import Series #定义,可以混合定义 x=Series(['a',True,1],index=['first','...
  • Series和DataFrame的简单数学运算

    千次阅读 2020-08-08 13:27:11
    Series和DataFrame的简单数学运算Series和DataFrame的简单数学运算操作学习引入相关库Series的数学运算DataFrame的运算DataFrame内置的运算 Series和DataFrame的简单数学运算操作学习 import numpy as np import ...

空空如也

1 2 3 4 5 ... 20
收藏数 66,749
精华内容 26,699
关键字:

series