pandas: powerful Python data analysis toolkit - 0.25frame: cheese <- data.frame( first = c('John', 'Mary'), last = c('Doe', 'Bo'), height = c(5.5, 6.0), weight = c(130, 150) ) melt(cheese, id=c("first", "last")) In Python, the melt() method is the R equivalent: 6.0], ....: 'weight': [130, 150]}) ....: In [33]: pd.melt(cheese, id_vars=['first', 'last']) Out[33]: first last variable value 0 John Doe height 5.5 1 Mary Bo height 6.0 2 John Doe weight 130.0 3 Mary Mary Bo weight 150.0 In [34]: cheese.set_index(['first', 'last']).stack() # alternative way Out[34]: first last John Doe height 5.5 weight 130.0 Mary Bo height 6.0 weight 150.0 dtype: float64 3.5. Comparison0 码力 | 698 页 | 4.91 MB | 1 年前3
pandas: powerful Python data analysis toolkit - 0.25.0'cat', 'dog'], ...: 'height': [9.1, 6.0, 9.5, 34.0], ...: 'weight': [7.9, 7.5, 9.9, 198.0]}) ...: In [2]: animals Out[2]: kind height weight 0 cat 9.1 7.9 1 dog 6.0 7.5 2 cat 9.5 9.9 3 dog 34.0 198 aggfunc='min'), ...: max_height=pd.NamedAgg(column='height', aggfunc='max'), ...: average_weight=pd.NamedAgg(column='weight', aggfunc=np.mean), ...: ) ...: \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\Out[3]: ˓→ min_height max_height average_weight kind cat 9.1 9.5 8.90 dog 6.0 34.0 102.75 [2 rows x 3 columns] Pass the desired columns names0 码力 | 2827 页 | 9.62 MB | 1 年前3
pandas: powerful Python data analysis toolkit - 0.25.1'cat', 'dog'], ...: 'height': [9.1, 6.0, 9.5, 34.0], ...: 'weight': [7.9, 7.5, 9.9, 198.0]}) ...: In [2]: animals Out[2]: kind height weight 0 cat 9.1 7.9 1 dog 6.0 7.5 2 cat 9.5 9.9 (continues on aggfunc='min'), ...: max_height=pd.NamedAgg(column='height', aggfunc='max'), ...: average_weight=pd.NamedAgg(column='weight', aggfunc=np.mean), ...: ) ...: \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\Out[3]: ˓→ min_height max_height average_weight kind cat 9.1 9.5 8.90 dog 6.0 34.0 102.75 [2 rows x 3 columns] Pass the desired columns names0 码力 | 2833 页 | 9.65 MB | 1 年前3
pandas: powerful Python data analysis toolkit - 1.0.0frame: cheese <- data.frame( first = c('John', 'Mary'), last = c('Doe', 'Bo'), height = c(5.5, 6.0), weight = c(130, 150) ) melt(cheese, id=c("first", "last")) In Python, the melt() method is the R equivalent: DataFrame({'first': ['John', 'Mary'], ....: 'last': ['Doe', 'Bo'], ....: 'height': [5.5, 6.0], ....: 'weight': [130, 150]}) (continues on next page) 174 Chapter 2. Getting started pandas: powerful Python Doe weight 130.0 3 Mary Bo weight 150.0 In [34]: cheese.set_index(['first', 'last']).stack() # alternative way Out[34]: first last John Doe height 5.5 weight 130.0 Mary Bo height 6.0 weight 1500 码力 | 3015 页 | 10.78 MB | 1 年前3
pandas: powerful Python data analysis toolkit - 1.1.1frame: cheese <- data.frame( first = c('John', 'Mary'), last = c('Doe', 'Bo'), height = c(5.5, 6.0), weight = c(130, 150) ) melt(cheese, id=c("first", "last")) In Python, the melt() method is the R equivalent: ....: 'weight': [130, 150]}) ....: In [33]: pd.melt(cheese, id_vars=['first', 'last']) Out[33]: first last variable value 0 John Doe height 5.5 1 Mary Bo height 6.0 2 John Doe weight 130.0 3 Mary Mary Bo weight 150.0 In [34]: cheese.set_index(['first', 'last']).stack() # alternative way Out[34]: first last John Doe height 5.5 weight 130.0 Mary Bo height 6.0 (continues on next page) 1.4.0 码力 | 3231 页 | 10.87 MB | 1 年前3
pandas: powerful Python data analysis toolkit - 1.1.0frame: cheese <- data.frame( first = c('John', 'Mary'), last = c('Doe', 'Bo'), height = c(5.5, 6.0), weight = c(130, 150) ) melt(cheese, id=c("first", "last")) In Python, the melt() method is the R equivalent: ....: 'weight': [130, 150]}) ....: In [33]: pd.melt(cheese, id_vars=['first', 'last']) Out[33]: first last variable value 0 John Doe height 5.5 1 Mary Bo height 6.0 2 John Doe weight 130.0 3 Mary Mary Bo weight 150.0 In [34]: cheese.set_index(['first', 'last']).stack() # alternative way Out[34]: first last John Doe height 5.5 weight 130.0 Mary Bo height 6.0 (continues on next page) 1.4.0 码力 | 3229 页 | 10.87 MB | 1 年前3
pandas: powerful Python data analysis toolkit - 1.4.2frame: cheese <- data.frame( first = c('John', 'Mary'), last = c('Doe', 'Bo'), height = c(5.5, 6.0), weight = c(130, 150) ) melt(cheese, id=c("first", "last")) In Python, the melt() method is the R equivalent: .: "first": ["John", "Mary"], ....: "last": ["Doe", "Bo"], ....: "height": [5.5, 6.0], ....: "weight": [130, 150], ....: } ....: ) ....: In [33]: pd.melt(cheese, id_vars=["first", "last"]) Out[33]: Doe weight 130.0 3 Mary Bo weight 150.0 In [34]: cheese.set_index(["first", "last"]).stack() # alternative way Out[34]: first last John Doe height 5.5 weight 130.0 Mary Bo height 6.0 weight 1500 码力 | 3739 页 | 15.24 MB | 1 年前3
pandas: powerful Python data analysis toolkit - 1.4.4frame: cheese <- data.frame( first = c('John', 'Mary'), last = c('Doe', 'Bo'), height = c(5.5, 6.0), weight = c(130, 150) ) melt(cheese, id=c("first", "last")) In Python, the melt() method is the R equivalent: .: "first": ["John", "Mary"], ....: "last": ["Doe", "Bo"], ....: "height": [5.5, 6.0], ....: "weight": [130, 150], ....: } ....: ) ....: In [33]: pd.melt(cheese, id_vars=["first", "last"]) Out[33]: Doe weight 130.0 3 Mary Bo weight 150.0 In [34]: cheese.set_index(["first", "last"]).stack() # alternative way Out[34]: first last John Doe height 5.5 weight 130.0 Mary Bo height 6.0 weight 1500 码力 | 3743 页 | 15.26 MB | 1 年前3
pandas: powerful Python data analysis toolkit - 1.0frame: cheese <- data.frame( first = c('John', 'Mary'), last = c('Doe', 'Bo'), height = c(5.5, 6.0), weight = c(130, 150) ) melt(cheese, id=c("first", "last")) In Python, the melt() method is the R equivalent: ....: 'weight': [130, 150]}) ....: In [33]: pd.melt(cheese, id_vars=['first', 'last']) Out[33]: first last variable value 0 John Doe height 5.5 1 Mary Bo height 6.0 2 John Doe weight 130.0 3 Mary Mary Bo weight 150.0 In [34]: cheese.set_index(['first', 'last']).stack() # alternative way Out[34]: first last John Doe height 5.5 weight 130.0 Mary Bo height 6.0 weight 150.0 dtype: float64 For0 码力 | 3091 页 | 10.16 MB | 1 年前3
pandas: powerful Python data analysis toolkit - 1.0.4frame: cheese <- data.frame( first = c('John', 'Mary'), last = c('Doe', 'Bo'), height = c(5.5, 6.0), weight = c(130, 150) ) melt(cheese, id=c("first", "last")) In Python, the melt() method is the R equivalent: ....: 'weight': [130, 150]}) ....: In [33]: pd.melt(cheese, id_vars=['first', 'last']) Out[33]: first last variable value 0 John Doe height 5.5 1 Mary Bo height 6.0 2 John Doe weight 130.0 3 Mary Mary Bo weight 150.0 In [34]: cheese.set_index(['first', 'last']).stack() # alternative way Out[34]: first last John Doe height 5.5 weight 130.0 Mary Bo height 6.0 weight 150.0 dtype: float64 For0 码力 | 3081 页 | 10.24 MB | 1 年前3
共 32 条
- 1
- 2
- 3
- 4













