解决FutureWarning: .ix is deprecated.

案例如下:

import pandas as pd
data = [[1,2,3],[4,5,6],[7,8,9]]
rows = ['row1','row2','row3']#行标签
columns = ['col1','col2','col3']#列标签
df = pd.DataFrame(data, index=rows, columns=columns)
print df

1.loc函数

使用方法(row1就是行标签)

print df.loc['row1']

运行结果:

col1    1
col2    2
col3    3
Name: row1, dtype: int64

2.iloc函数

使用方法(0就是行号)

print df.iloc[0]

运行结果:

col1    1
col2    2
col3    3
Name: row1, dtype: int64

3.ix函数

使用方法(loc和iloc的结合)

print df.ix[0]
print df.ix['row1']
print df.ix['row1',‘col1’]
print df.ix['row1',0]

运行结果:

col1    1
col2    2
col3    3
Name: row1, dtype: int64
col1    1
col2    2
col3    3
Name: row1, dtype: int64
1
1
发布了301 篇原创文章 · 获赞 30 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/weixin_42260102/article/details/104210432