切片熊猫系列

时间:2019-11-21 21:07:15

标签: python-3.x pandas slice

我有以下代码:

postgres=# create table foo (id text, name text);
CREATE TABLE
postgres=# insert into foo values (generate_series(95,105),'foo');
INSERT 0 11
postgres=# select * from foo where id > 100;
ERROR:  operator does not exist: text > integer
LINE 1: select * from foo where id > 100;
                                   ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.
postgres=# select * from foo where to_number(id,'99999') > 100;
 id  | name 
-----+------
 101 | foo
 102 | foo
 103 | foo
 104 | foo
 105 | foo
(5 rows)

但是我希望99999postgres=# select * from foo where id::int > 100; id | name -----+------ 101 | foo 102 | foo 103 | foo 104 | foo 105 | foo (5 rows)

目前,我阅读total_csv = pd.read_csv('total.csv',header=0).iloc[:,:] column28=total_csv ['28'] column27=total_csv ['27'] column26=total_csv ['26'] column25=total_csv ['25'] column24=total_csv ['24'] column23=total_csv ['23'] master_values=(column23,column24,column25,column26,column27,column28) In [68]:master_values Out[68]: (0 6867.488928 Name: 23, dtype: float64, 0 6960.779317 Name: 24, dtype: float64, 0 7007.540137 Name: 25, dtype: float64, 0 7031.11444 Name: 26, dtype: float64, 0 7127.469389 Name: 27, dtype: float64, 0 7408.207806 Name: 28, dtype: float64) 的方式如下:

master_values

我怎样才能将(6867.488928,6960.779317,7007.540137,7031.11444,7127.469389,7408.207806)读为total_csv

2 个答案:

答案 0 :(得分:0)

columnXX变量是否必要?

也许只是尝试以下操作: master_values = pd.read_csv('total.csv',header = 0).iloc [0]

,如果您需要括号中所示的元组,可以这样做: master_values = tuple(pd.read_csv('total.csv',header = 0).iloc [0])

答案 1 :(得分:0)

您可以尝试以下方法:

total_csv.to_numpy()[0][0].split('  ')[1:]