I am trying to create a pandas dataframe with one row using and ended up testing the following simple line of code:
df = pd.DataFrame([1,2,3,4], columns=['a', 'b', 'v', 'w'])
Although this seems very simple i get the following error
Shape of passed values is (1, 4), indices imply (4, 4)
I have seen a few answers on this issues but all provide a way around it that doesn't explain why this happens and does not apply in my case.
Thanks is advance.
But for now here's my answer: DataFrame is 2 dimensional, and its index are rows and columns (2 indexes) .
The shape of a DataFrame is a tuple of array dimensions that tells the number of rows and columns of a given DataFrame. The DataFrame. shape attribute in Pandas enables us to obtain the shape of a DataFrame.
Definition and Usage The shape property returns a tuple containing the shape of the DataFrame.
For numeric data, the result's index will include count , mean , std , min , max as well as lower, 50 and upper percentiles. By default the lower percentile is 25 and the upper percentile is 75 . The 50 percentile is the same as the median.
you need to change the list of values to [[1,2,3,4]]
df = pd.DataFrame([[1,2,3,4]], columns=['a', 'b', 'v', 'w'])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With