1

As im tring to fetch specific data based on u_id for ploting graph and predicting market rate.For Example: I have 1000 data in my excel sheet and the U_ID is 5 i want to fetch U_ID 5th entire data. My Data Format is..

enter image description here

Above Screen shot is my excel format input data and i want to fetch data based on U_ID..if the U_ID is 2 means i want to fetch all data includes P_ID,Products(Spoons,cups),Product Quantity,Total amount,location,date.

i tried but still i did not get my expected output.

import pandas as pd
from pandas import DataFrame as df
from pandas import *
import matplotlib.pyplot as plt
from selenium.webdriver.common import by
excel_file = 'FIRST1.xls'
mov = pd.read_excel(excel_file)
# print(mov)
DataFrame(mov, columns=["SNO",  "U_ID", "P_ID", "SUBPRODUCTS",  "PRODUCT QUANTITY", "TOTAL AMOUNT", "LOCATION", "DATE"])
mov.sort_values(by="U_ID", inplace=True)
# df.sort_values(by='PURCHASE AMOUNT')
print (mov.iloc[1])
getda = mov.iloc[1]
gd = getda[1]
od = getda[4]

It give the data as sorted form..Any one help me.. Thanks In Advance

petezurich
  • 9,280
  • 9
  • 43
  • 57
Sruthipriyanga
  • 468
  • 4
  • 17

1 Answers1

2

Try this:

import pandas as pd
import matplotlib.pyplot as plt

excel_file = 'FIRST1.xls'
df = pd.read_excel(excel_file)
df.columns = ["SNO",  "U_ID", "P_ID", "SUBPRODUCTS",  "PRODUCT QUANTITY", "TOTAL AMOUNT", "LOCATION", "DATE"]

getda = df[df.U_ID == 2].values # <- .values gives you the values of your data row as a list!

gd = getda[1]
od = getda[4]

If you have more than one row that meets the condition then interate over the results (which is a list of lists):

for row in getda:
    gd = row[1]
    od = row[4]
petezurich
  • 9,280
  • 9
  • 43
  • 57
  • Thank You for your try..@petezurich actually my actual output is if the U_ID is 2 means i should fetch all column where the U_ID is 2. [3 2.0 2 'Spoons' 10 200 'hosur' Timestamp('2017-01-03 00:00:00') and 4 2.0 2 'Cups' 1 1500 'chennai' 04/01/2017] – Sruthipriyanga Oct 15 '18 at 08:24
  • @PriyaSRI You´re welcome. And regarding your comment see my editied answer. – petezurich Oct 15 '18 at 08:34