df.groupby([col1,col2]) | Returns groupby object for values from multiple columns df.groupby(col1)[col2] | Returns the mean of the values in col2, grouped by the values in col1 (mean can be replaced with almost any function from the statistics section) df.pivot_table(index=col1,val...
df.groupby(col1)[col2] | Returns the mean of the values in col2, grouped by the values in col1 (mean can be replaced with almost any function from the statistics section) df.pivot_table(index=col1,values=[col2,col3],aggfunc=mean) | Create a pivot table that groups by col1 and ...
我的选择是这5个,截图均来自pandas官方cheat sheet和官方api文档。大家有英文阅读能力的都建议去看官方...
Transform data with ease! This Pandas cheat sheet is your key to sorting, analyzing, and visualizing like an expert.
(filename) - Saves as an HTML table any function from the statistics section) df1.append(df2) - Adds the rows in df1 to the df.to_clipboard() - Writes to the clipboard s.astype(float) - Converts the datatype of the end of df2 (columns should be identical) series to float pd....
Apply Function: df['column'].apply(lambda x: function(x)) Group By and Aggregate: df.groupby('column').agg({'column': 'sum'}) Pivot Tables: df.pivot_table(index='column1', values='column2', aggfunc='mean') Merge DataFrames: pd.merge(df1, df2, on='column') Concatenate Data...
The Pandas cheat sheet will guide you through the basics of the Pandas library, going from the data structuresto I/O, selection, dropping indices or columns, sorting and ranking, retrieving basic information of the data structures you're working with to applying functions and data alignment. In...
>>> df Even Odd021143265l ·Apply function>>> df.apply(lambda x: x*2) Even Odd04218621210 数据对齐 在这一部分,你将学习如何对具有不同索引的两个Series进行加、减和除。 下面是代码中的s和s3在这一部分用作Series的示例。 >>> sa6b-5c7d4>>> s3a7c-2d3l ·Internal Data Alignment>>> s +...
literal_eval(x)) # an even shorter alternative is to apply the # function directly (without lambda) ted.ratings.apply(ast.literal_eval) # 索引 index 使用 apply() df.index.to_series().apply() 15 样式显示 代码语言:javascript 复制 # https://pbpython.com/styling-pandas.html df['per_...
20 向数据框应用一个函数 df1.apply(function1)df1.applymap(function1) 21 merge 两个数据框 df3=pd.merge(df1,df2,on='id') 22 concate 两个数据框 df4=pd.concat([df1,df2]) REF:Pandas Cheat Sheet: top 35 commands and operations