pd.concat()进行数据拼接
https://www.jianshu.com/p/421f040dfe2f
pd.concat(objs, axis=0, join=‘outer’)
合并多个对象时需要放到一个列表中;axis=0默认按照0轴堆叠,axis=1指合并列;concat函数可按照其他轴的逻辑关系进行合并,默认join=‘outer’,表示所有轴都需要,还有一个可取的值是’inner’,表示只取重合的部分。
df.fillna()函数详解
DataFrame数据结构的空值的填充
https://blog.csdn.net/weixin_39549734/article/details/81221276
df.unique()函数详解
将np数组或者DataFrame数组进行元素去重,并返回一个新的已经排序好的不重复的数组
https://blog.csdn.net/weixin_39549734/article/details/81224567
Python map() 函数
https://www.runoob.com/python/python-func-map.html
map(function, iterable, …)
map() 会根据提供的函数对指定序列做映射。
第一个参数 function 以参数序列中的每一个元素调用 function 函数,返回包含每次 function 函数返回值的新列表。
>>>def square(x) : # 计算平方数
... return x ** 2
...
>>> map(square, [1,2,3,4,5]) # 计算列表各个元素的平方
[1, 4, 9, 16, 25]
pandas里面的isin()函数:
https://blog.csdn.net/u013317445/article/details/86428584
比如:有两个DataFrame A 和 B,判断A[‘id’]里面的值是否在B[‘id’]里面
如下面用法:
>>> dict = {'a':[1,2,3,4],'b':[11,12,12,14],'c':[22,21,10,19],'d':[33,23,23,43],'e':[51,52,53,54]}
# 以字典创建一个DataFrame结构的a
>>> a = pd.DataFrame(dict)
>>> a
a b c d e
0 1 11 22 33 51
1 2 12 21 23 52
2 3 12 10 23 53
3 4 14 19 43 54
# 下面判断a['a']这一列的值是否有在[1,4]里面的,其结果返回一个bool类型的Series
>>> a['a'].isin([1,4])
0 True
1 False
2 False
3 True
Name: a, dtype: bool
# 在前面加一个~表示不在,如下,表示a['a']这一列中不在[1,4]这两个元素里面的
# 也是返回一个布尔类型的Series
>>> ~a['a'].isin([1,4])
0 False
1 True
2 True
3 False
Name: a, dtype: bool
pd.date_range():pandas中的时间序列函数
https://blog.csdn.net/kancy110/article/details/77131539
语法:pandas.date_range(start=None, end=None, periods=None, freq=‘D’, tz=None, normalize=False, name=None, closed=None, **kwargs)
该函数主要用于生成一个固定频率的时间索引,在调用构造方法时,必须指定start、end、periods中的两个参数值,否则报错。
主要参数说明:
periods:固定时期,取值为整数或None
freq:日期偏移量,取值为string或DateOffset,默认为’D’,可以选择‘M’(月份)、‘Y’(年),也有’A’(每年12.31号)
normalize:若参数为True表示将start、end参数值正则化到午夜时间戳
name:生成时间索引对象的名称,取值为string或None
closed:可以理解成在closed=None情况下返回的结果中,若closed=‘left’表示在返回的结果基础上,再取左开右闭的结果,若closed='right’表示在返回的结果基础上,再取做闭右开的结果
pandas的stack和unstack函数:
# 这里有原始的DataFrame的a矩阵
>>> a
a b c
time
2019-09-16 1 4 7
2019-09-17 2 5 8
2019-09-18 3 6 9
# 堆叠发现是按照行进行堆叠,即axis = 0
>>> a.stack()
time
2019-09-16 a 1
b 4
c 7
2019-09-17 a 2
b 5
c 8
2019-09-18 a 3
b 6
c 9
dtype: int64
# 换用axis=1试一下发现报错,说明只能默认按行堆叠
>>> a.stack(1)
IndexError: Too many levels: Index has only 1 level, not 2
# 这个即默认的方式
>>> a.stack(0)
time
2019-09-16 a 1
b 4
c 7
2019-09-17 a 2
b 5
c 8
2019-09-18 a 3
b 6
c 9
dtype: int64
# 现在采用不堆叠的方式,即是将columns进行展开,也只有一种方式,axis为0或者1都是一样的。
>>> a.unstack()
time
a 2019-09-16 1
2019-09-17 2
2019-09-18 3
b 2019-09-16 4
2019-09-17 5
2019-09-18 6
c 2019-09-16 7
2019-09-17 8
2019-09-18 9
dtype: int64
>>> a.unstack(0)
time
a 2019-09-16 1
2019-09-17 2
2019-09-18 3
b 2019-09-16 4
2019-09-17 5
2019-09-18 6
c 2019-09-16 7
2019-09-17 8
2019-09-18 9
dtype: int64
>>> a.unstack(1)
time
a 2019-09-16 1
2019-09-17 2
2019-09-18 3
b 2019-09-16 4
2019-09-17 5
2019-09-18 6
c 2019-09-16 7
2019-09-17 8
2019-09-18 9
dtype: int64
>>>
本文介绍了Pandas中的数据拼接方法pd.concat(),详细讲解了如何使用fillna()处理空值,以及df.unique()去除重复值。还探讨了Python的map()函数,解释了isin()函数在DataFrame中的应用,并阐述了date_range()生成时间序列的功能,以及stack和unstack函数的基本用法。

968

被折叠的 条评论
为什么被折叠?



