如何使用键(名称)在.csv或.xls文件中获取输出值(地址)?

时间:2019-12-12 04:13:27

标签: python pandas dataframe

Sl。编号,名称,地址

1.,Stuart,华尔街

2.,Charlie,Broadway

3.Oliver,Hollywood Boulevard

4.,Harry,Las Vegas Boulevard

5.,Kyle,Bourbon Street

o / p将像:

print(Stuart) >>>  Wall Street

1 个答案:

答案 0 :(得分:0)

将csv导入pandas dataframe并使用loc

import pandas as pd
df = pd.read_csv('/Users/prince/Downloads/test2.csv', sep=',')
df = df.set_index('Name')
print(df.loc['Stuart']['Address'])

给出以下输出

Wall Street