Informatics Practices
Why does the following code cause error?
s1 = pd.Series(range 1, 15, 5), index = list('ababa')
print(s1['ab'])
Python Data Handling
2 Likes
Answer
The statement s1['ab'] causes an error because 'ab' is not a single key in the index. The index has individual keys 'a' and 'b', but not 'ab'.
Answered By
1 Like
Related Questions
Find the error in the following code fragments:
S2 = pd.Series([1, 2, 3, 4, 5], index = range(4))Find the Error :
data = np.array(['a', 'b', 'c', 'd', 'e', 'f']) s = pd.Series(data, index = [100, 101, 102, 103, 104, 105]) print(s[102, 103, 104] )Can you correct the error ?
Consider the following Class12.csv file containing the data as given below:
RollNo Name Accounts Maths BSt IP Eco 10 Ritu Jain 88 67 87 97 56 11 Mridul Mehta 67 78 77 87 90 12 Divij 87 89 78 82 92 13 Yashvi Verma 67 82.3 76.5 98.2 78.6 14 Deepak Virmani 56.7 76.5 88 78 67 15 Jatin Malik 76 66 77 87.5 67.5 (a) Read the csv file into a dataframe df which is stored with tab ('\t') separator.
(b) Write the code to find the total marks (Total_ marks) for each student and add it to the newly-created dataframe.
(c) Also calculate the percentage obtained by each student under a new column “Average” in the dataframe.
Write a program that reads students marks from a ‘Result.csv’ file and displays percentage of each student.