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)
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.
Hey @IanAtCSTeach , 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!
I’m somewhat late to this, but the reason you’re encountering that error is that the scores are provided as a single string rather than as a list of strings or integers. In a DataFrame, each key-value pair in the dictionary corresponds to a column, with the key serving as the column name and the value as the list of column values. All columns must have the same number of elements.
import pandas as pd
data_dict = {
"students": ["Amy", "James", "Angela"],
"scores": [76, 56, 65] # Provide the scores as a list of integers
}
data = pd.DataFrame(data_dict)
print(data)