csv列没有过滤,没有错误

时间:2017-02-28 07:56:08

标签: python pandas indexing conditional-statements

文件:

SYMBOL,DATE1,PREV_CLOSE,CLOSE_PRICE,DELIV_QTY,DELIV_PER,P/L_PER
20MICRONS,23-Feb-2017,36.55,35.9,41182,76.49,-1.77838577291
3IINFOTECH,23-Feb-2017,5.3,5.25,1240915,60.45,-0.943396226415
3MINDIA,23-Feb-2017,11135.85,11038.15,360,69.50,-0.877346587822
63MOONS,23-Feb-2017,80.3,80.6,26958,53.38,0.373599003736
63MOONS,23-Feb-2017,80.3,80.6,26958,53.38,0.373599003736
8KMILES,23-Feb-2017,588.75,586.75,10141,46.50,-0.339702760085
A2ZINFRA,23-Feb-2017,40.95,40.55,116344,48.67,-0.97680097680

根据我的代码和输入文件,它应该按照条件输出列DELIV_QTY的所有行,但是当我运行代码时,没有错误,文件也没有变化。

请更正我的代码。

import pandas as pd
df = pd.read csv('bhavcopy.csir', index_col = False) 
df[df.DELIV QTY >= 10000 ]
df.to csv('bhavcopy.csir', index = False)

1 个答案:

答案 0 :(得分:1)

您需要将输出分配到df,因为JSON Web Tokens无法正常工作:

df = df[df.DELIV_QTY >= 10000]
print (df)
       SYMBOL        DATE1  PREV_CLOSE  CLOSE_PRICE  DELIV_QTY  DELIV_PER  \
0   20MICRONS  23-Feb-2017       36.55        35.90      41182      76.49   
1  3IINFOTECH  23-Feb-2017        5.30         5.25    1240915      60.45   
3     63MOONS  23-Feb-2017       80.30        80.60      26958      53.38   
4     63MOONS  23-Feb-2017       80.30        80.60      26958      53.38   
5     8KMILES  23-Feb-2017      588.75       586.75      10141      46.50   
6    A2ZINFRA  23-Feb-2017       40.95        40.55     116344      48.67   

    P/L_PER  
0 -1.778386  
1 -0.943396  
3  0.373599  
4  0.373599  
5 -0.339703  
6 -0.976801  

boolean indexing的另一个解决方案:

df = df.query('DELIV_QTY >= 10000')
print (df)
       SYMBOL        DATE1  PREV_CLOSE  CLOSE_PRICE  DELIV_QTY  DELIV_PER  \
0   20MICRONS  23-Feb-2017       36.55        35.90      41182      76.49   
1  3IINFOTECH  23-Feb-2017        5.30         5.25    1240915      60.45   
3     63MOONS  23-Feb-2017       80.30        80.60      26958      53.38   
4     63MOONS  23-Feb-2017       80.30        80.60      26958      53.38   
5     8KMILES  23-Feb-2017      588.75       586.75      10141      46.50   
6    A2ZINFRA  23-Feb-2017       40.95        40.55     116344      48.67   

    P/L_PER  
0 -1.778386  
1 -0.943396  
3  0.373599  
4  0.373599  
5 -0.339703  
6 -0.976801