+ 4

.shape syntax

Python data manipulation

20th Feb 2022, 8:25 PM
Kyle Yarun Parsotan
17 Answers
+ 3
It may help if you print out the variable 'dt' as it is just before the error, and then look at how you are trying to retrieve the data from dt, what you actually expect to get from it. Then fix your indexing/slicing accordingly.
20th Feb 2022, 11:19 PM
ChaoticDawg
ChaoticDawg - avatar
+ 2
@everyone Could anyone provide some incite on something with python? I am working on writing the problem: The problem is that I am trying to manipulate and play with some data and I and creating a for loop to limit the data to specific lat and long for the storm I want to use. I was told to use the following: see image attached. On line 22 I am getting the following error: typeerror: 'int' object is not iterable. I tried to look up what the .shape does and it shows the rows and columns in the data set but it is not working in this case.
20th Feb 2022, 8:25 PM
Kyle Yarun Parsotan
+ 2
I am using numpy, seaborn, subprocess( which is a Linux thing that be used in python), pandas, and matplotlib but these imports are for the stats process and data manipulation except the subprocess.
20th Feb 2022, 8:26 PM
Kyle Yarun Parsotan
20th Feb 2022, 9:30 PM
Kyle Yarun Parsotan
+ 2
for i in btdata.shape[0]: the shape property of a pandas dataframe returns a tuple of integers of the dimensions of that dataframe. Therefore the 0th index of the shape property will be an int of the size of that dimension. An int is not a iterable type. This is why you're receiving the error here.
20th Feb 2022, 10:13 PM
ChaoticDawg
ChaoticDawg - avatar
+ 2
It needed the range(btdata.shape[0])
20th Feb 2022, 10:20 PM
Kyle Yarun Parsotan
+ 2
I am having another problem after I fixed that problem. It is invalid index to scalar variable line 33
20th Feb 2022, 10:21 PM
Kyle Yarun Parsotan
+ 2
Kyle Y Parsotan You may have several issues throughout your programs. It may be best if you try to solve your errors and issues. Think about what the error means, look it up (Google) if unsure, and where it is pointing you toward. Line 33 is meaningless to me (for the most part), as the shared code doesn't match up with the given lines and I can't run this code to check its operation. I could easily infer the last error and could probably figure this error out if I wished to, but I feel it more important for you to make a more asserted attempt at solving the issue(s). If after you have searched and attempted to learn what the error(s) are and can describe the issue more thoroughly, provide your current version of your code as is without modification along with the error, so that the information is relative, I'll then do my best to help further.
20th Feb 2022, 10:51 PM
ChaoticDawg
ChaoticDawg - avatar
+ 2
I Googled the error and I couldn't find what I was looking for.
20th Feb 2022, 11:09 PM
Kyle Yarun Parsotan
+ 2
I Googled the other error at first and found that it needed the range() before the btdata.shape[0] parameter.
20th Feb 2022, 11:10 PM
Kyle Yarun Parsotan
+ 2
This is where the error is occurring: year = dt[0:4] #select the year see posted code
20th Feb 2022, 11:11 PM
Kyle Yarun Parsotan
+ 2
This is what I found when I Googled 'python invalid index to scalar variable' https://codesource.io/how-to-solve-invalid-index-to-scalar-variable/ Give it a read through and see how it may correlate to your error and line 33 etc.
20th Feb 2022, 11:13 PM
ChaoticDawg
ChaoticDawg - avatar
+ 2
That's what I looked at. I will look at it again
20th Feb 2022, 11:13 PM
Kyle Yarun Parsotan
+ 2
I did print out dt. it works it is after that the slicing and indexing like you said. I looked up the format for the iloc and loc since that was being used for dt.
20th Feb 2022, 11:28 PM
Kyle Yarun Parsotan
+ 2
It prints out the 2020051006 something like that
20th Feb 2022, 11:32 PM
Kyle Yarun Parsotan
+ 2
And in the next line I am slicing dt into sections.
20th Feb 2022, 11:32 PM
Kyle Yarun Parsotan
+ 2
I figured out the problem it was just str() because the parameter that was being printed and stored is a string so it required str()
27th Feb 2022, 1:39 PM
Kyle Yarun Parsotan