0
df=pd.DataFrame[columns='one','two','three']

for home in city:
    adres= home
    for a in abc: #abc is pd.Series od names
        #here i want to add values - adress and a , but my dataframe have 3 columns, i will use only 2 here
         df.loc[len(df)]= [adres, a, np.nan]
          print(df)
one, two, three
alabama, flat, NaN

How propery should i add values adres and a to one and two column in df and leave column three untouchable?

thank you

2 Answers 2

1

I think you are looking for something like:

for i in range(1):
    df.loc[i,['one','two']]=['adress','a']
print(df)

      one two three
0  adress   a   NaN
Sign up to request clarification or add additional context in comments.

Comments

0

I would first create a pandas series that contain the values and columns I want. for example:

new_values= pd.Series(["a", "b"], index=["one", "two"])

Then I would append this series to the original dataframe:

df= df.append(new_values, ignore_index=True)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.