How To Use User Input To Select Row Column And Return Cell Value?
I have a pandas dataframe constructed from a csv file. I ask the user for two values, separated by a space. I then attempt to do a pandas.loc[,] to return that cell value. How do
Solution 1:
Let A
be
A = pd.DataFrame(
np.random.randint(10, size=(10, 10)),
list('abcdefghij'), list('ABCDEFGHIJ'))
A B C D E F G H I J
a 1803577271
b 7766113439
c 8494672815
d 1024051796
e 9032366950
f 5620792080
g 7705261901
h 5807407317
i 9962773509
j 3180189759
Grab user input... Notice the assignment to i
and j
. You had a split
but were only grabbing the first value in the split
i, j = input('>>> ').split()
>>> i C
A.loc[i, j]
6
Post a Comment for "How To Use User Input To Select Row Column And Return Cell Value?"