重塑数据框架(使用R或Python)

时间:2017-05-31 13:36:20

标签: python r dataframe

我想知道是否可以得到这个结果:

exemple

使用此数据框

df
      y Faisceaux destination Trajet RED_Groupe Nbr observation RED       Pond Nbr observation total       RED        pct
1  2015        France DOM-TOM  Aller   78248.47                  87   85586.75                   307 0.9142591 0.04187815
2  2015         Hors Schengen  Aller  256817.64                 234  195561.26                  1194 1.3132337 0.06015340
3  2015         INTERNATIONAL  Aller  258534.78                 473  288856.53                  2065 0.8950283 0.04099727
4  2015               Maghreb  Aller  605514.45                 270  171718.14                  1130 3.5262113 0.16152007
5  2015              NATIONAL  Aller  361185.82                 923 1082529.19                  5541 0.3336500 0.01528302
6  2015              Schengen  Aller  312271.06                 940  505181.07                  4190 0.6181369 0.02831411
7  2015        France DOM-TOM Retour   30408.70                  23   29024.60                   108 1.0476871 0.04798989
8  2015         Hors Schengen Retour  349805.15                 225  168429.96                   953 2.0768583 0.09513165
9  2015         INTERNATIONAL Retour  193536.63                 138   99160.52                   678 1.9517509 0.08940104
10 2015               Maghreb Retour  302863.83                 110   41677.90                   294 7.2667735 0.33285861
11 2015              NATIONAL Retour  471520.80                 647  757258.33                  3956 0.6226684 0.02852167
12 2015              Schengen Retour  307691.66                 422  243204.76                  2104 1.2651548 0.05795112

不使用Exel。 用R还是Python?我不知道是否可以拆分列。

1 个答案:

答案 0 :(得分:0)

感谢此处的所有评论我的解决方案:

我将数据框拆分为两个数据框df15(包含2015年数据)和df16(2016年数据):

mytable15 <- tabular(Heading()*Faisceaux_destination ~ Trajet*(`RED_Groupe` + `Nbr observation RED` + Pond + `Nbr observation total` + RED + pct)*Heading()*(identity),data=df15)
mytable16 <- tabular(Heading()*Faisceaux_destination ~ Trajet*(`RED_Groupe` + `Nbr observation RED` + Pond + `Nbr observation total` + RED + pct)*Heading()*(identity),data=df16)