Can we find a value that meets the condition and return the corresponding key value to make it a list?
For example,
listA = year = [1950,1951,...,2018]
listB = index = [value1,value2,...,value69]
I made dictionary data so that year is key and index is value by combining these two lists.
dic = {1950:value1, 1951:value2, ..., 2018:value69} If the value is greater than 1, can the corresponding key value be returned?
For example, if the two values are 1, 1.2 and the rest are all less than 1
Can I get [1951, 2017]
in the form of a list of 1951, 2017 corresponding to these two keys?
I'd appreciate your help.
python
l = [ k for k, v in dic.items() if v >=1 ]
import pandas as pd
df = pd.DataFrame({ "year":listA, "value":listB })
df[df.value >= 1].year
© 2024 OneMinuteCode. All rights reserved.