class Data(object):
def __init__(self):
self.name = list(rank.values())[0]
dataset = Data()
I want to extract only the first name from the dictionary named Rank in the picture and save it in the list, what should I do?
dictionary class python
self.name = [ v[0] for v in rank.values()]
>>> import pandas as pd
>>> df = pd.DataFrame([["jeff", "188B", "us"],["elon", "170B", "us"]])
>>> df
0 1 2
0 jeff 188B us
1 elon 170B us
>>> df = pd.DataFrame([["jeff", "188B", "us"],["elon", "170B", "us"]], columns=["name", "wealth", "nation"])
>>> df
name wealth nation
0 jeff 188B us
1 elon 170B us
data = pd.DataFrame(rank.values(),
columns=[ "name", "wealth", "wealth_delta1", "wealth_delta2", "nationality", "business area" ])
© 2024 OneMinuteCode. All rights reserved.