문제

A have a data frame with State Abbreviation and Full State Name.

How do I take a state abbreviation and lookup the Full Sate Name? Its so simple but I just can't figure it out.

stateDF = pandas.read_csv("c:\\states.csv", index_col=0)

targetState = "AL"

fullName = stateDF.ix(targetState,"Full Name")
도움이 되었습니까?

해결책

How about:

stateDF[stateDF['abbreviation_column'] == targetState]['Full Name']

Where 'abbreviation_column' is the name of the column where the abbreviation resides. This will find all rows that have the targetState variable in the abbreviation column and return only the Full_Name value.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top