how to use the input with pandas to get all the value.count linked to this input

Viewed 65

my dataframe looks like this:

Index(['#Organism/Name', 'TaxID', 'BioProject Accession', 'BioProject ID', 'Group', 'SubGroup', 'Size (Mb)', 'GC%', 'Replicons', 'WGS',
    'Scaffolds', 'Genes', 'Proteins', 'Release Date', 'Modify Date',
       'Status', 'Center', 'BioSample Accession', 'Assembly Accession',
       'Reference', 'FTP Path', 'Pubmed ID', 'Strain'],
      dtype='object')

I ask the user to enter the name of the species with this script :

print("bacterie species?")
species=input()

I want to look for the rows with "Organism/Name" equal to the species written by the user (input) then to calculate with "values.count" of the status column and finally to retrieve 'FTP Path'. Here is the code that I could do but that does not work:

if (data.loc[(data["Organism/Name"]==species)
  print(Data['Status'].value_counts()) 
else:
    print("This species not found")

if (data.loc[(data["Organism/Name"]==species)
  print(Data['Status'].value_counts()) 
else:
    print(Data.get["FTP Path"]
1 Answers

If I understand your question correctly, this is what you're trying to achieve:

import wget
import numpy as np 
import pandas as pd    

URL='https://ftp.ncbi.nlm.nih.gov/genomes/GENOME_REPORTS/prokaryotes.txt'

data = pd.read_csv(wget.download(URL) , sep = '\t', header = 0)

species = input("Enter the bacteria species: ")   

if data["#Organism/Name"].str.contains(species, case = False).any():

    print(data.loc[data["#Organism/Name"].str.contains(species, case = False)]['Status'].value_counts())    
   
    FTP_list = data.loc[data["#Organism/Name"].str.contains(species, case = False)]["FTP Path"].values

else:    
    print("This species not found")

To wite all the FTP_Path urls into a txt file, you can do this:

with open('/path/urls.txt', mode='wt') as file:
    file.write('\n'.join(FTP_list))
Related