[英]Multiply Python Pandas dataframes together to get product of values in column
[英]Get last column of pandas dataframes using python
如何获得dataFrame中的最后一列(或“ nth”)?
df = pd.read_csv(csv_file)
col=df.iloc[:,0] #returns Index([], dtype='object')
col2=df.iloc[:,-1] #returns the whole dataframe
col3=df.columns[df.columns.str.startswith('c')] #returns Index([], dtype='object')
代码后被注释掉的部分是我在打印后得到的。 大多数时候,我会得到“ returns Index([],dtype ='object')”之类的信息
这是df打印的内容:
date open high low close
0 0 2019-07-09 09:20:10 296.235 296.245 296...
1 1 2019-07-09 09:20:15 296.245 296.245 296...
2 2 2019-07-09 09:20:20 296.235 296.245 296...
3 3 2019-07-09 09:20:25 296.235 296.275 296...
df.iloc
可以引用行和列。 如果仅输入一个整数,它将自动引用一行。 您可以混合使用索引和列的索引器类型。 使用:
选择整个轴。
df.iloc[:,-1:]
将打印出所有最后一列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.