I am reading a csv file using python and displaying the record after asking the user to select an index and then I display all the records corresponding to the index number.
Code:
df = pd.read_csv(csv_filepath, usecols=['userID', 'firstName', 'lastName'])
select_index = int(input("Enter the Index of Claimant: "))
data = df.loc[select_index, :]
print(data)
userID = data.userID
firstName = data.firstName
lastName = data.lastName
print(claimantID)
print(Claimant_FirstName)
print(Claimant_LastName)
The above code works perfectly fine and I am able to print the values.
Now I want to create a variable called as x and store userID + firstName + lastName .
If I do this I am getting error. What can be the issue.
Basically if I write
x = userID + firstName + lastName
I get the following error:
numpy.core._exceptions.UFuncTypeError: ufunc 'add' did not contain a loop with signature matching types (dtype('int64'), dtype('<U4')) -> None
>Solution :
The problem is with coloumn types.
Example:
import pandas as pd
df = pd.DataFrame({'userID': [1], 'firstName': ['a'], 'lastName':['b']})
data = df.loc[0, :]
userID = data.userID
firstName = data.firstName
lastName = data.lastName
#solution
x = str(userID) + firstName + lastName
result:
