If you have any questions, comments or issues with this project please post them here!
Iām on Day 25 and lesson 228. Toward the end of the lesson, import pandas, Create a dataframe from scratch . when the instructor runs the program it comes out ok but when I run it I get an error.
ValueError: All arrays must be of the same length.
import pandas
# Create a dataframe from scratch.
import pandas
data_dict = {
"students": ["Amy", "James", "Angela"],
"scores": ["76, 56, 65"]
}
data = pandas.DataFrame(data_dict)
print(data)
Is Replit 101 a good platform to go to ask questions being that is seems to be relatively new?
Thank you @BrittanyatReplit. What about my āDataFrame from scratch question?ā Iāve noticed a lot of questions on askreplit that others have posted with copies of their code questions. iām new at posting. Was my format incorrect and if so how should I be submitting copies of code?
You can format code with ```
I did it for you this time so donāt worry about it. Some more info is in this guide. Unfortenly I donāt know pandas so I cant assist you.
You can also create an invite link and share the link here so other users can look at your code directly to help you out.
Hey All
New here and first question re the Day25 lesson. Iām familiar with subroutines and passing/returning variables. But I do admit Iām struggling a bit with how Python does āsubā things.
First, the example uses the same variable āareaā both inside and outside the subroutine. This seems bad coding practice and a recipe for disaster if someone else is trying to interpret your code. I was taught to never do this, so I donāt. I might use the variable āarea_sā inside the sub, and āareaā outside, for example.
Is it common practice among Python coders to use the same variable inside/outside the sub? Do I need to change my outlook on this?
Second, I am used to having a substantial main program, followed by subroutines. In the example, the main program consists of a line or two at the end of the sub, and the meat of the code is the sub located at the top. Can I switch the order, and have the main program first and the sub second?
Thanks!
Hi @QZapper thanks for your question.
I think the issue is with the following line of code:
"scores": ["76, 56, 65"]
You need to remove the quotes before the number 76 and after the number 65 as below:
"scores": [76, 56, 65]
The program then works correctly. Iāve made a copy here for reference https://replit.com/@IanAtReplit/Day25#main.py
Hi @chartanalyst welcome to the community and thanks for your question!
I teach and have been a programmer for a while. I understand why you name your variables differently inside and outside of the subroutine to help recognise local and global variables however Iād argue it is personal preference. In some high school / college courses you would submit your program alongside a document with a variable table and perhaps even a data flow diagram too.
In answer to your second question Iāve always been taught and have taught to have subroutines at the top and main program at the end of the code. However if it works for you to reverse this to complete the 100daysofcode challenges then I would suggest you go for it!
Hope you are enjoying the challenges and keep posting to the community!
Hey @IanAtReplit , thank you so much for that correction. I am a rookie so I guess I shouldnāt fell as bad as I do for not catching that clumsy error. I swore I looked at everything. Thank you.
Hi @QZapper never a problem! Thanks for the thanks but we keep learning all the time. 39 years programming and still make the odd mistake that takes me a while to see!
Built a character health stats generator to prepare for the epic battle in 3 days!!
https://replit.com/@JackAdem/Day-025-Project-25-Character-stats-generator?v=1
Day 25 of #Replit100DaysOfCode #100DaysOfCode.
Ngl, it took me too much time and I was so stuck but finally I made through