last day (17 days later) » 

11:51 PM
0
Q: Error message : x and y must have same first dimension, but have shapes (23,) and (1,)

Aghyad SkaifI have an excel file and I wanna plot a specific range of rows in a specific column I could get the access to the column and rows that I wanted but whenever I run my code this error message turns up x and y must have same first dimension, but have shapes (23,) and (1,) the first row of the...

 
You plot time vs z. But z is the result of the sum function so it's a number. time and z must have the same dimension as the error is telling you. Maybe, if you provide a sample of you datasheet, we could reproduce it.
 
my data sheet has 20 columns that represent the electricity consumption of 19 houses where each column is a house and the first columns represents the time, I wanna plot the average monthly consumption with respect to time, the time column consists of the hourly time of each house so 720 hour is a month. I calculate the sum of the first 720 rows to plot the consumption of the first month, can u please tell me what can I add to my code to do that
 
Can you edit your post with the first rows of your dataframes data_generation2 and data_consumption ?
 
Both sheet are almost the same with different values, I`ve added the photo in the post
not all the houses had a value at the beginning thats why some of the values are null. Each house has a code which is a column name.
 
What do you mean by the respect of time column ? In a chronological order ? Do you want to plot a cumulative sum ? for each house ?
 
11:51 PM
I mean by with respect the time the following: the sheet that I have has a time column and this column has values of time "dates&hour" for example: the first row declares that in 10-Mar-2019 at 1:00 PM the consumption of the first house was x and the second house was y and go on I wanna plot the consumption with respect to that time for example: I wanna take the first 24 rows which indicates the first day, then I wanna plot the corresponding consumption values to that time which is the first 24 rows of the rest of the columns
In my code I`ve taken the first 720 rows which is 24*30 coz I wanted to plot the monthly consumption I wish it is clear now
I will try it out I really appreciate that and thank to your kindness sir!
I will try it out I really appreciate that and thank to your kindness sir!
 
Glad to help you ! Feel free to vote up or down for the answer and/or accept it if that answer.
 
one last thing when im running the "to_datetime" statement, an exception is turning up KeyError: 'Timestamp' it sounds like the name of the column has not written correctly but I make sure that it is correct what do u think of this error?
 
You should call it from pandas and not from the dataframe object. It's a method from pandas module. For example, you can do something like this: import pandas as pd and then pd.to_datetime(...)
 
this is the statement in my code data_consumption2["Timestamp"]=pd.to_datetime(data_consumpti‌​on2["Timestamp"], format="%d/%m/%y %H%M:%S") I`ve already called it from Pandas
 
Oups, I read to fast. Yes you're right. The error message with KeyError mean the column doesn't exist. Are you sure to have a Timestamp column ?
 
11:51 PM
yes I`m pretty sure I just copied it from my sheet, it is the first column that indicates the date and I copied it from the column name with regard to the letter sensitivity
 
Can you update your question with the code and the column sheetname (if they are different from those already present in the question) ?
 
Ok I think the error message from the following statement data_generation= data_generation2.loc[start_date:end_date] data_consumption = data_consumption2.loc[start_date:end_date] there is an KeyError: '2017-07-24 00:00:00'
I make all the statements separated in my jupyter notebook and the error was there I`m gna update the question once I write the code completely really thank u :) :)
regardless of the plotting, thats my code that import the excel file and transform the date and filter by date. I`m having key errors!
-> 4200 raise ValueError('index must be monotonic increasing or decreasing') would it be that the value of the start date is wrong ?
 
Yes, the error come from data_generation = data_generation2.loc[start_date:end_date]. The loc function expect a true / false array. Basically, you write a condition in the loc brackets. (doc). What do you want to do by this line ?
 
actually I just want and access a group of values using labels do u think I can replace this line by something else that does the same?
or can I edit the same statement to be correct and without errors?
 
It's possible to use loc. I advise you to have a look at my answer, I did it at this line : df_to_plot = data_generation2.loc[(data_generation2.Date >= start_date) & (data_generation2.Date < end_date)] to filter according date interval
 
11:51 PM
I tried it out but how come the error tells me that the daraframe object has no attribute "Timestamp" would it be possible that there is an error in the excel file?
 
Yes, for sure you "Timestamp" should be missing. Just display it before you call the column "timestamp" to see what there is in. You can do it by just print(my_dataframe). If you want to get all the columns names of your dataframe, you can use my_dataframe.columns.
 
when I print my dataframe out it did not show the timestamp column, eventhough the column is definetily in the excel file, kindly check the image above u can see it clearly, its the first column on your left hand side u can only see the word "mestam" but it is "Timestamp" and thats how does it look in this picture
should I convert the Timestamp column from the 10-digits format to the date format by using a certain formula before my code? because it is 10-digits format in the Excel
 
Are you sure to read the right file ? Pandas reads all columns by default. If one column isn't displayed after the datasheet is read, that means this column isn't in the datasheet. It's hard to help you with that.
 
what uve done was really enough, I appreciate that so much, Ill make sure of the source of the file coz I`ve got it by email, thanks a lot sir!
 
You're welcome. Glad to help you :)
 

  last day (17 days later) »