1

I am trying to add a single value to a row of a dataframe each time a for loop goes by. What I did was:

df1= pd.read_csv('data1.csv')
df2= pd.read_csv('data2.csv')
df3 = pd.DataFrame()

for i in df1.index:
    for j in df2.index:
        some_name = df1['some name'].iloc[j]
        other_name = df2['other name'].iloc[i]
        range = j
        df3 = df3.set_value(i, some_name, range)
        df3 = df3.set_value(i, 'Cargo', other_name)

What I ment to do is this:

enter image description here

But what I am getting is that in the first iteration the values are right but when I get to the second iteration my df3 becomes empty.

UPDATE

My df1 column, which is the only one in this table that I am using, would be like:

enter image description here

And my df2 column, which is the only one in this table that I am using, would be like:

enter image description here

Matheus Sant'ana
  • 563
  • 2
  • 6
  • 23
  • 2
    Please provide your sample csv files. – Prince Francis Dec 07 '18 at 01:16
  • Sorry, I can't. Think that the values of the column df1['some name'].iloc[j] would be ['some name value 1', 'some name value 2', 'some name value 3', 'some name value 4']. The same works with the other value. – Matheus Sant'ana Dec 07 '18 at 01:29
  • 2
    @MatheusSant'ana your odds of getting useful feedback will go up if you add a copy-pastable sample fake data and desired output. No need to upload your actual data. – hilberts_drinking_problem Dec 07 '18 at 01:36
  • Please see [How to ask](https://stackoverflow.com/help/how-to-ask) and [How to create a MCVE](https://stackoverflow.com/help/mcve). For `pandas`, see [How to ask a good pandas question](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). – Evan Dec 07 '18 at 04:44

0 Answers0