Hi sir/ma’am, in the loop its written row which according to the table is Casey 176544.328149. But we have to convert only 176544.328149 this into float as per the question, then why we have selected the entire row. if we have to convert columns then why row is written. Not getting.
type(row) means in row 0, first element i.e Estimated column? correct me and guide me. Thanks in advance.
if i print row i am getting,
and so on
if i print row,
and so on
if i print row,
and so on
why is this represented in column form? if i printed row. i am still confused and struggling. So please give me a direct answer And explanation rather then telling me to fish for answer. thanks
after printing all this if i print row it shows e. what is e? still i don’t understand what is row. you can refer my question and tell me if i understood right or wrong.
Direct answers are only helpful when you have broken down the problem yourself first. Breaking down the problem allows you to observe and understand patterns. Observing and understanding patterns allows you to create mental models to be able to solve more problems and debug any similar issues you might face in the future.
In a for loop, if you include a print statement, it will print out the content line-by-line for every iteration of that loop. That’s why it’s printing out the values line by line as you observe.
You printed out row, what did you get?
The first output -
What is this?
The first list in your list of lists.
You printed out row. What did you get?
The first output -
Casey is the first item in the above list that you printed out.
How do you obtain an element from a list in Python?
Using indexing. In Python, indexing starts at 0. So, the first item is obtained using the index 0. That’s what row returns.
Given the above information, what will row return?
row returned the list above. row returned the first item from that list, which was a stringCasey. So, row will return the item at index 1 in the stringCasey.
What are the individual items in the stringCasey?
“C”, “a”, “s”, “e”, “y”
Which item from the above is at index 1?
And that’s what you will get from row when the row is [‘Casey’, 176544.328149]
Stop and Think
What would you get if you printed out row? Think about the answer first. Then print it out in your code to cross-check if you got it right. This will help you ensure you understood the above properly.
There are multiple concepts here that you don’t currently seem fully comfortable with. I would recommend going through the courses/Missions that cover the Python basics around print statements and indexing again to improve your understanding. I would also recommend going through the basics of for loops and lists as well.
ok got you but i was struggling since six days so. i print row i am getting e instead of a. i mentioned this in above reply.
also if i print row i should get 5 right? i visualized like you said but i am getting this
TypeErrorTraceback (most recent call last)
—> 11 print(row)
And what is row here? If it’s not the same as [‘Casey’, 176544.328149] then you won’t get an a.
If you are trying to print rowoutside of the for loop, then your row would be the last list in rows. Because your for loop completed all iterations, so row now has the last value only outside of that loop.
The lastrow in rows is ['Aeon', '100.21104', 4]. Therefore, as you can see, you will get an e from row if you print outside of the for loop.
That’s a good question. You should get a 5ifrow is of the string datatype.
You can use type() to check the datatype of the value store. For example, print(type(row))
As the error states, the datatype seems to be float in your case. Which is not subscriptable. That is, you can’t extract the individual numbers from that float using indexing. That’s only applicable to strings or elements in a list, for example.
The row for each row in rows is of string datatype. And you need to convert them to float as per the problem statement. So, if you printed out rowbefore you converted it to float, you would have indeed obtained 5 for the ['Casey', '176544.328149'] row.
The above might be a lot of information to take in. So, go through it at your own pace.
Nope i got this reply of yours in seconds. I was already visualizing this as i have converted into float, the error is there, if it was a string like in the original question then i would’ve got 5 right? Anyway now i got what exactly row means and why it gave output ‘str’ because row inside for loop is a which is str.
Using the type() function, print the data type of the estimated number column in the first data row. this was the second question. So did we checked the right? As per this question shouldn’t we check row something because the estimated column has index row.
“Using the type() function, print the data type of the estimated number column in the first data row”. This was the second question asked to test the answer, in which we did print(type(row) but that gives us ‘a’ , right?. but here we are asked to check the data type of the estimated number column. which is this row - 176544.328149 so its index is  as per we discussed above. so thats what i was asking that shouldnt we check row[any index] rather then checking row which gives us ‘name’ column and not the ‘estimated _number’ column as asked in the testing question.
No, it won’t give us a. You are checking for the datatype with type(). So, that would return the datatype of row.
You are confusing between row and rows.
type(rows) (notice the s) will give you the datatype of the value in the estimated_number column for the first list (rows, notice the s here too). This is what they are asking to test the answer with.
type(row[any index]) will give you the datatype of the value at any index in row where row would be a list in rows.
yeah sorry i meant, it will give us str. and without type it will give ‘a’.
yes i saw now that it is rows instead of what i wrote. so rows means the header row and in that  means the estimated number one, so it gave me float as answer when i checked the type, because we converted into float as per asked in the question. If we didnt convert than it would return str by default right? please tell me i got everything right now. if yes then Thank you for explaining everything to me and bearing with me. Thank you so much doctor.
yes now i got it all rows is what we print excluding the header row. And we want the type for second value from the first list which is rows which we converted from str to float. i took too much time to understand but got it. Thanks a lot
hi sir in the above conversation we discussed that to check the type we used type(rows) to get the float value. So why in the image above we used app to get the value of price? we can use app_and_price? I am confused. Or when getting the float value in the above discussion we can use type(row). Can you clear this for me? @the_doctor
but my doubt is related to this question. if i will create another post then you eventually have to come here to check what we discussed. To make your work easier i posted here becauseMY DOUBT IS IN CONTINUATION WITH OUR DICUSSION i will appreciate if you answer it here.
I answered the original question. And your new question can be answered by that same discussion.
In my previous replies to your original question I did two things -
Ask you to print out values and focus on understanding what happens in your code.
Break down the process, step-by-step, through asking yourself questions and answering those questions.
If you can follow the above two steps and be specific about why you are still confused given my previous responses to your original question, I can try to answer here. But based on what you have shared of your new problem, my previous responses should help you out.
If you don’t wish to be specific about it, that’s absolutely fine as well. But in that case, I would highly suggest that you create a new question with the appropriate link (to the practice problem or Mission) and details, and someone else from the community can surely help you out soon enough.
sometimes you have to look from other people’s perspective, how can i post a new question if my doubt was related to this question? I have always followed rules while posting questions. Nvm i will try to google and understand if i can, because i don’t know i will create a new post and then ask you to come here and see the doubt, posting here was easy for YOU to review. I never said that i don’t want to be specific. Totally NOT satisfied with the community experience so far.