2
嗨我需要根据列值选择所有行,将其存储在一个新的变量中,或者创建一个新的数据帧并将其保存到没有头文件的csv中, 。根据列值选择所有的行pandas
import pandas as pd
import numpy as np
print(df)
# 0 1 2 3
# 0 Gm# one 0 0
# 1 922 one 1 2
# 2 933 two 2 4
# 3 952 three 3 6
# 4 Gm# two 4 8
# 5 960 two 5 10
# 6 963 one 6 12
# 7 999 three 7 14
所以我想要一个基于第一列条件的新数据框。我只想抓取范围为>= 900 & <=999
的行。所需的输出:
我想将它存储在没有索引的csv中。
print (df2)
922 one 1 2
933 two 2 4
952 three 3 6
960 two 5 10
963 one 6 12
999 three 7 14
我尝试这样做:问题我得到我无法弄清楚如何将孔列转换成integers..or也许还有一个更简单的方式通过这样做只是参考,而不是检查孔的数据帧在堆栈溢出和YouTube视频的各种文章,但只是不能正确的。任何想法,我会很乐意欣赏它。
#df[x]= data[x][(data[x]['0'].astype(np.int64))] need to find a away to convert the column [0] into integer for it evaluate
#df2 = data[i]([(data['0'] >= 900) & (data['0'] <= 999)])
哎我得到这个错误我只是改变了你给我的东西,并得到这个错误。 tables [i] .iloc [:, 0] = tables [i] .to_numeric(tables [i] .iloc [:, 0],errors ='coerce') 文件“C:\ Python35 \ lib \ site我不使用'tables [i]'包装\ pandas \ core \ generic.py“,第2669行,在__getattr__ 返回对象.__ getattribute __(self,name) AttributeError:'DataFrame'object has no attribute'to_numeric' – herrington
但是, ',但'表' – jezrael
请检查我的解决方案,我添加测试DataFrame。 – jezrael