![](/img/trans.png)
[英]Can we insert values of one column from one data frame to another column of another dataframe based on index using python?
[英]Get data from one column based on another using Python
當我提供的數據與column2和column4中的數據匹配時,我正在嘗試從.xlsx文件的column1中獲取數據。 我嘗試使用data[data['column2'] == "aa1"]
但對結果不滿意。 對於column4數據,我使用了int(raw_input("get data: "))
但這也不起作用。
示例excel文件:
column1,column2,column3,column4
aa,aa1,lll,21
bb,aa2,ll,22
要求的輸出:
aa #when an input of aa1 and 21 is given.
PS-數據為熊貓數據框的形式。
你要這個:
data[(data['column2'] == "aa1") & (data['column4'] == 21)]
因此,要使用多個條件,您需要使用&
而不是and
因為我們正在比較數組,由於運算符的優先級,您還需要使用括號
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.