0

I want to pick one user name (Test_1) from below csv and use it as an input. After finishing program run for this username I want to run my program for another username (Test_2).

enter image description here

I could take user input as below and save into 'myinput'

import pandas as pd
from pandas import DataFrame
import matplotlib.pyplot as plt
import time
start_time = time.time()

myinput = input('Enter the word to find\n :')  

I tried using below code to get value from UserName.

df = pd.read_csv("DatatoSearch.csv", usecols = ['DataSearch'])
for(int row = 0;row <= df.getRows();row++)

But not able to get the user names one by one and get assigned to 'myinput' value.

Thanks !

ADS KUL
  • 33
  • 1
  • 9
  • Use `df[df['DataSearch'] == myinput]` – jezrael Mar 06 '20 at 07:39
  • Thanks jezrael, but it is not working. It is giving an error as 'myinput' is not defined.I want to pick first username and with that my program will run then once that round finished and I get data using first user name, system will go into loop for every username and return the result till I reached at the last user name. Thanks ! – ADS KUL Mar 06 '20 at 07:42
  • None of reference answer suggested are not matching to my question. – ADS KUL Mar 06 '20 at 07:47
  • So if use `print (myinput)` not working? There is no typo? – jezrael Mar 06 '20 at 07:48
  • I could print all the data of usernames and that is not a problem. I just want my program to pick first user name and give it to my program as an input and then run the program. Once my program run finished it should go to another username to pick it and process will be keep going till last username. – ADS KUL Mar 06 '20 at 07:54
  • So need `next(iter(df.loc[df['DataSearch'] == myinput, 'DataSearch']), 'no match username')` ? – jezrael Mar 06 '20 at 07:56
  • It is giving an error as 'myinput' is not defined. – ADS KUL Mar 06 '20 at 08:29
  • Myabe help [this](https://stackoverflow.com/questions/21122540/input-error-nameerror-name-is-not-defined) – jezrael Mar 06 '20 at 08:31
  • No, the code myinput = input('Enter the word to find\n :') is for my user input. I want to comment that code and need to write new code for input values from mentioned csv one by one. – ADS KUL Mar 06 '20 at 08:32
  • So need first dupe like `for x in df['DataSearch']: print (x)` ? – jezrael Mar 06 '20 at 08:33
  • I repeat no issue with user input. Only requirement is, instead of user input program should pick the username from csv and that is as one by one. – ADS KUL Mar 06 '20 at 08:33
  • for x in df['DataSearch']: print (x), it prints all the values of my coloum ie from Test_1 to Willo. I want my program to pick Test_1 and then it will fetch the data and done for first user name. Now it will go to csv and pick Test_2 and fetch the data... and so on.. – ADS KUL Mar 06 '20 at 08:36
  • Have u closed this question? No solutions suggested by other Members hence asking. – ADS KUL Mar 06 '20 at 08:38
  • ` I want my program to pick Test_1` it is already done by `x`. `I want my program to pick Test_1 and then it will fetch the data and done for first user name.` - What is code for `fetch data` ? – jezrael Mar 06 '20 at 08:39
  • data = table[ table["detail"].str.contains(myinput)] print(data) Here I will get the data from my table named 'detail'. myinput is a username which mentioned in csv. So I want to put username one by one in 'myinput'. – ADS KUL Mar 06 '20 at 08:43
  • `for x in df['DataSearch']: data = table[ table["detail"].str.contains(x)]` – jezrael Mar 06 '20 at 08:44
  • 1
    It worked... finally. Thanks! It is successfully checking all the user names and printing data for it. Well, Previously when I was taking user input I put a code to save data in new CSV by user defined name to csv. so can I add that small code after every user name read. filename = input('Enter the name you would like to give to your CSV \n :') data.to_csv('path'+ filename +'.csv',index=False) Thanks! – ADS KUL Mar 06 '20 at 09:06
  • Supeerr, glad can help ;) – jezrael Mar 06 '20 at 09:07

0 Answers0