Why does shape return the size (xxxx, ) for my pandas dataframe and not (xxxx, 1)? [duplicate]











up vote
0
down vote

favorite













This question already has an answer here:




  • Difference between numpy.array shape (R, 1) and (R,)

    5 answers




I'm using train_test_split with my dataframe, my code looks something like this:



df = pd.read_csv('data.csv', header=None)
y = df[0]
X_train, X_test, y_train, y_test = train_test_split(df, y,test_size=0.2, random_state=0)


When I print y.shape or y_train.shape it's returning (2871,). When I print y or y_train it returns what I would expect, a list of all the y values in my file so why is the shape not (2871, 1)?










share|improve this question















marked as duplicate by ayhan pandas
Users with the  pandas badge can single-handedly close pandas questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 10 at 19:34


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















    up vote
    0
    down vote

    favorite













    This question already has an answer here:




    • Difference between numpy.array shape (R, 1) and (R,)

      5 answers




    I'm using train_test_split with my dataframe, my code looks something like this:



    df = pd.read_csv('data.csv', header=None)
    y = df[0]
    X_train, X_test, y_train, y_test = train_test_split(df, y,test_size=0.2, random_state=0)


    When I print y.shape or y_train.shape it's returning (2871,). When I print y or y_train it returns what I would expect, a list of all the y values in my file so why is the shape not (2871, 1)?










    share|improve this question















    marked as duplicate by ayhan pandas
    Users with the  pandas badge can single-handedly close pandas questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Nov 10 at 19:34


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite












      This question already has an answer here:




      • Difference between numpy.array shape (R, 1) and (R,)

        5 answers




      I'm using train_test_split with my dataframe, my code looks something like this:



      df = pd.read_csv('data.csv', header=None)
      y = df[0]
      X_train, X_test, y_train, y_test = train_test_split(df, y,test_size=0.2, random_state=0)


      When I print y.shape or y_train.shape it's returning (2871,). When I print y or y_train it returns what I would expect, a list of all the y values in my file so why is the shape not (2871, 1)?










      share|improve this question
















      This question already has an answer here:




      • Difference between numpy.array shape (R, 1) and (R,)

        5 answers




      I'm using train_test_split with my dataframe, my code looks something like this:



      df = pd.read_csv('data.csv', header=None)
      y = df[0]
      X_train, X_test, y_train, y_test = train_test_split(df, y,test_size=0.2, random_state=0)


      When I print y.shape or y_train.shape it's returning (2871,). When I print y or y_train it returns what I would expect, a list of all the y values in my file so why is the shape not (2871, 1)?





      This question already has an answer here:




      • Difference between numpy.array shape (R, 1) and (R,)

        5 answers








      python pandas






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 19:24

























      asked Nov 10 at 19:18









      jj2593

      122




      122




      marked as duplicate by ayhan pandas
      Users with the  pandas badge can single-handedly close pandas questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 10 at 19:34


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by ayhan pandas
      Users with the  pandas badge can single-handedly close pandas questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 10 at 19:34


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          That's just how numpy prints out 1-dimensional arrays. Pandas uses numpy under the hood for dataframes, so you get that shape. Once you go to 2-dimensional and higher, you'll start seeing more values in the shape tuple. Some examples from numpy's documentation






          share|improve this answer





















          • Ok thanks. I realized my issue was I made a numpy array with the code array = np.zeros((1, 58)) which was my issue. Although this leads me to the question, why is it if I transpose that array it has the shape (58, 1) but my y dataframe has the shape (2871, ). Shouldn't the numpy zero array have the shape (58, ) ?
            – jj2593
            Nov 10 at 19:48










          • I believe that is because the first array is actually a 2D array in memory. Although the transposition logically makes it 1D, it is still a 2D object. The link this was marked duplicate as has an interesting discussion with visuals of how the 1D case is treated. Without looking at the code, I assume most numpy functions operate with 1D as a special case, and nD as a general case.
            – ahota
            Nov 10 at 19:53


















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          That's just how numpy prints out 1-dimensional arrays. Pandas uses numpy under the hood for dataframes, so you get that shape. Once you go to 2-dimensional and higher, you'll start seeing more values in the shape tuple. Some examples from numpy's documentation






          share|improve this answer





















          • Ok thanks. I realized my issue was I made a numpy array with the code array = np.zeros((1, 58)) which was my issue. Although this leads me to the question, why is it if I transpose that array it has the shape (58, 1) but my y dataframe has the shape (2871, ). Shouldn't the numpy zero array have the shape (58, ) ?
            – jj2593
            Nov 10 at 19:48










          • I believe that is because the first array is actually a 2D array in memory. Although the transposition logically makes it 1D, it is still a 2D object. The link this was marked duplicate as has an interesting discussion with visuals of how the 1D case is treated. Without looking at the code, I assume most numpy functions operate with 1D as a special case, and nD as a general case.
            – ahota
            Nov 10 at 19:53















          up vote
          0
          down vote













          That's just how numpy prints out 1-dimensional arrays. Pandas uses numpy under the hood for dataframes, so you get that shape. Once you go to 2-dimensional and higher, you'll start seeing more values in the shape tuple. Some examples from numpy's documentation






          share|improve this answer





















          • Ok thanks. I realized my issue was I made a numpy array with the code array = np.zeros((1, 58)) which was my issue. Although this leads me to the question, why is it if I transpose that array it has the shape (58, 1) but my y dataframe has the shape (2871, ). Shouldn't the numpy zero array have the shape (58, ) ?
            – jj2593
            Nov 10 at 19:48










          • I believe that is because the first array is actually a 2D array in memory. Although the transposition logically makes it 1D, it is still a 2D object. The link this was marked duplicate as has an interesting discussion with visuals of how the 1D case is treated. Without looking at the code, I assume most numpy functions operate with 1D as a special case, and nD as a general case.
            – ahota
            Nov 10 at 19:53













          up vote
          0
          down vote










          up vote
          0
          down vote









          That's just how numpy prints out 1-dimensional arrays. Pandas uses numpy under the hood for dataframes, so you get that shape. Once you go to 2-dimensional and higher, you'll start seeing more values in the shape tuple. Some examples from numpy's documentation






          share|improve this answer












          That's just how numpy prints out 1-dimensional arrays. Pandas uses numpy under the hood for dataframes, so you get that shape. Once you go to 2-dimensional and higher, you'll start seeing more values in the shape tuple. Some examples from numpy's documentation







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 10 at 19:30









          ahota

          34828




          34828












          • Ok thanks. I realized my issue was I made a numpy array with the code array = np.zeros((1, 58)) which was my issue. Although this leads me to the question, why is it if I transpose that array it has the shape (58, 1) but my y dataframe has the shape (2871, ). Shouldn't the numpy zero array have the shape (58, ) ?
            – jj2593
            Nov 10 at 19:48










          • I believe that is because the first array is actually a 2D array in memory. Although the transposition logically makes it 1D, it is still a 2D object. The link this was marked duplicate as has an interesting discussion with visuals of how the 1D case is treated. Without looking at the code, I assume most numpy functions operate with 1D as a special case, and nD as a general case.
            – ahota
            Nov 10 at 19:53


















          • Ok thanks. I realized my issue was I made a numpy array with the code array = np.zeros((1, 58)) which was my issue. Although this leads me to the question, why is it if I transpose that array it has the shape (58, 1) but my y dataframe has the shape (2871, ). Shouldn't the numpy zero array have the shape (58, ) ?
            – jj2593
            Nov 10 at 19:48










          • I believe that is because the first array is actually a 2D array in memory. Although the transposition logically makes it 1D, it is still a 2D object. The link this was marked duplicate as has an interesting discussion with visuals of how the 1D case is treated. Without looking at the code, I assume most numpy functions operate with 1D as a special case, and nD as a general case.
            – ahota
            Nov 10 at 19:53
















          Ok thanks. I realized my issue was I made a numpy array with the code array = np.zeros((1, 58)) which was my issue. Although this leads me to the question, why is it if I transpose that array it has the shape (58, 1) but my y dataframe has the shape (2871, ). Shouldn't the numpy zero array have the shape (58, ) ?
          – jj2593
          Nov 10 at 19:48




          Ok thanks. I realized my issue was I made a numpy array with the code array = np.zeros((1, 58)) which was my issue. Although this leads me to the question, why is it if I transpose that array it has the shape (58, 1) but my y dataframe has the shape (2871, ). Shouldn't the numpy zero array have the shape (58, ) ?
          – jj2593
          Nov 10 at 19:48












          I believe that is because the first array is actually a 2D array in memory. Although the transposition logically makes it 1D, it is still a 2D object. The link this was marked duplicate as has an interesting discussion with visuals of how the 1D case is treated. Without looking at the code, I assume most numpy functions operate with 1D as a special case, and nD as a general case.
          – ahota
          Nov 10 at 19:53




          I believe that is because the first array is actually a 2D array in memory. Although the transposition logically makes it 1D, it is still a 2D object. The link this was marked duplicate as has an interesting discussion with visuals of how the 1D case is treated. Without looking at the code, I assume most numpy functions operate with 1D as a special case, and nD as a general case.
          – ahota
          Nov 10 at 19:53



          Popular posts from this blog

          鏡平學校

          ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

          Why https connections are so slow when debugging (stepping over) in Java?