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)?
python pandas
marked as duplicate by ayhan
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.
add a comment |
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)?
python pandas
marked as duplicate by ayhan
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.
add a comment |
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)?
python pandas
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
python pandas
edited Nov 10 at 19:24
asked Nov 10 at 19:18
jj2593
122
122
marked as duplicate by ayhan
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
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.
add a comment |
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |