python - I want to get 2 rows and 3 columns when dictionary is given
问题描述
Retrieving 2 rows and 3 column using pandas
but the unable to it works in csv file but how to do when dictionary is given!?
import pandas as pd
data = {'Name':['Jai', 'Princi', 'Gaurav', 'Anuj'],
'Age':[27, 24, 22, 32],
'Address':['Delhi', 'Kanpur', 'Allahabad', 'Kannauj'],
'Qualification':['Msc', 'MA', 'MCA', 'Phd']}
df=pd.DataFrame(data)
df.set_index('Name')
f=df.loc[['Jai','Gaurav'],['Address','Age']]
print(f)
Still not working?
解决方案
df.set_index() shout be new object, try this instead df = df.set_index('Name')
推荐阅读
- ios - AR Kit 2.0 跟踪来自服务器的图像
- php - FFMPEG 没有“解码”正确的 url 输入
- python - Keras 时间序列输入形状
- c++ - 调用默认构造函数时模板可变参数编译错误
- html - Bootstrap 4.1.3,下拉菜单不起作用
- macos - 如何在 Mac 上安装 Homebrew?dyld:库未加载:@rpath/libssl.1.0.0.dylib
- qt - Cmake 在 QTCreator 中没有正确解析
- common-lisp - 如何获取函数的参数数量
- gradle - 如何在 gradle 中添加预处理任务
- wpf - WPF 将数据网格的值放入数据集中