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

          31628




          31628











          • 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

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          ReactJS Fetched API data displays live - need Data displayed static

          政党