Python Pandas库 常见使用错误总结
DataFrame对象的.ix[idx] 与 .ix[[idx]] 区别
# 示例
import numpy as np
import pandas as pd
# 创建一个10*3的DataFrame对象
df = pd.DataFrame(np.random.rand(10, 3))
'''
df: 0 1 2
0 0.619620 0.281018 0.449918
1 0.039654 0.778771 0.457885
2 0.905944 0.345189 0.859692
3 0.027250 0.676622 0.829580
4 0.230326 0.015882 0.556705
5 0.302833 0.121845 0.556206
6 0.944984 0.333118 0.291924
7 0.103753 0.688007 0.954185
8 0.326636 0.393403 0.153469
9 0.815440 0.519231 0.262114
'''
# 取出第4行(pandas.Series对象)
print(df.ix[4])
'''
0 0.230326
1 0.015882
2 0.556705
Name: 4, dtype: float64
'''
# 取出第4行,(pandas.DataFrame对象)
print(df.ix[[4]])
'''
0 1 2
4 0.230326 0.015882 0.556705
'''
本文标题:Python Pandas库 常见使用错误总结
本文链接:https://www.haomeiwen.com/subject/bepujttx.html
网友评论