So the question actually is the following:
I create the (straight copy paste from pandas documentation) dataframe:
d = {'col1': [1, 2], 'col2': [3, 4]}
df = pd.DataFrame(data=d)
This creates a a DataFrame like this: (where the left-most column is acutally the index)
col1 col2
0 1 3
1 2 4
Then I want to assign my name x
the value of the col2 and row1, which is 4. But I want to do this based on the value in col1 (cause thats the one I know). So that it looks more or less like this:
x = df.loc[df.col2 == df.loc[df.col1 == 2]]
I know this makes no sense, but maybe someone understands the issue and comes up with a hint:) Probably this is super easy to do, but I just can wrap my head around all the .loc and .iloc possibilities at the moment
The "real" problem is to write a class which saves the coordinates (columns lat, lon) based on the provided aiport name: (and this still is kind of confusing)
def __init__(self, name):
import pandas as pd
alleDaten = pd.read_csv("airports.dat", delimiter=",", usecols=[1,6,7])
alleDaten.columns = ["name","lat","lon"] #rename columns
self._name = alleDaten.loc[alleDaten.name == "name"] #get name based on the provided name of the airport
self._x = alleDaten.loc[alleDaten.name == "name", ["lat"]] # get lat based on the provided name
self._y = alleDaten.loc[alleDaten.name == "name", ["lon"]] # get lon based on the provided name
Thanks a lot for any help:)!!