正试图获取基于u_id的特定数据以绘制图表并预测市场价格,例如:我的excel工作表中有1000个数据,而U_ID为5我想获取U_ID的第5个完整数据。我的数据格式是..
以上屏幕快照是我的excel格式输入数据,我想基于U_ID提取数据。如果U_ID为2,则表示我要提取所有数据,包括P_ID,产品(勺子,杯子),产品数量,总数量,位置,日期。
我尝试过,但仍然没有得到预期的输出。
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]
它以排序形式给出数据。任何人都可以帮助我。 在此先感谢
答案 0 :(得分:2)
尝试一下:
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]
如果满足条件的行多于一列,则对结果进行迭代(这是列表的列表):
for row in getda:
gd = row[1]
od = row[4]