企业如何通过vue小程序开发满足高效运营与合规性需求
1025
2022-10-08
PyPackage01---Pandas11_explode方法使用
Intro
hive中有explode方法,进行单行转多行的操作。pandas也有类似的功能,versionadded:: 0.25.0。直接看个case。
Signature: df1.explode(column: Union[str, Tuple], ignore_index: bool = False) -> 'DataFrame'Docstring:Transform each element of a list-like to a row, replicating index values... versionadded:: 0.25.0Parameters----------column : str or tuple Column to explode.ignore_index : bool, default False If True, the resulting index will be labeled 0, 1, …, n - 1. .. versionadded:: 1.1.0Returns-------DataFrame Exploded lists to rows of the subset columns; index will be duplicated for these rows.Raises------ValueError : if columns of the frame are not unique.See Also--------DataFrame.unstack : Pivot a level of the (necessarily hierarchical) index labels.DataFrame.melt : Unpivot a DataFrame from wide format to long format.Series.explode : Explode a DataFrame from list-like columns to long format.Notes-----This routine will explode list-likes including lists, tuples,Series, and np.ndarray. The result dtype of the subset rows willbe object. Scalars will be returned unchanged. Empty list-likes willresult in a np.nan for that row.
Case
import pandas as
pd.__version__
'1.1.5'
id = ['a','b','c']id2 = [4,6,[2,3,8]]id3 = [1,1,1]df = pd.DataFrame({'id':id,'id2':id2,'id3':id3})
id | id2 | id3 | |
0 | a | 4 | 1 |
1 | b | 6 | 1 |
2 | c | [2, 3, 8] | 1 |
df.explode('id2')
id | id2 | id3 | |
0 | a | 4 | 1 |
1 | b | 6 | 1 |
2 | c | 2 | 1 |
2 | c | 3 | 1 |
2 | c | 8 | 1 |
2021-03-25 于南京市江宁区九龙湖
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~