0

So, I have a text document with many names and numbers in 2 separate columns, 1 column for numbers, 1 for names. I know how to take out the column of numbers, but it does not work on strings.

Code:

    import numpy as np

f = np.loadtxt("testfil.txt", int)
index = f[:, 0]

f = np.loadtxt("testfil.txt", str)
name = f[:, 1]

print(index, name)

The first part works with the integers, but with strings there´s a ValueError which says:

ValueError: could not convert string to float: 'James'

James is just the first name in the list.

PetterJY
  • 5
  • 1
  • 2
  • Why do you need a numpy array? Do you just need the numbers? – wwii Jan 29 '21 at 19:00
  • I´m fairly new to programming and used it in another project, so figured I would use it here as well. What I´m trying to do is: – PetterJY Jan 29 '21 at 19:01
  • make a Password, ID, Username program, so when i run the program i can chose to add another username and password to the program which is storied in 2 seperate text files, and have an ID that connects the 2, or i can chose to find the Password for the username, and anything else i would like afterwards. – PetterJY Jan 29 '21 at 19:02
  • But why do you need a numpy array? Doesn't seem like it offers anything to your project. – wwii Jan 29 '21 at 19:03
  • It´s basically just a project to get back my interest back into programming, since i have some programming classes in school, but there´s so much math that just make me bored of programming, so want to do something to reawaken the interest. – PetterJY Jan 29 '21 at 19:04
  • Just not sure any other ways i can bring out the entire column of usernames into a list – PetterJY Jan 29 '21 at 19:04
  • Welcome to SO. This isn't a discussion forum or tutorial. Please take the [tour] and take the time to read [ask] and the other links found on that page. – wwii Jan 29 '21 at 19:07

0 Answers0