0

I am trying to add rows to pandas dataframe incrementally inside the for loop.

My for loop is like below:

def print_values(cc):
    data = []
    for x in values[cc]:
        data.append(labels[x])
        # cc is a constant and data is a list. I need these values to be appended to a row in pandas dataframe.
        # Pandas dataframe structure is like follows: df=pd.DataFrame(columns = ['Index','Names'])
        print cc
        print data
        # This does not work - Not sure about the problem !!
        #df_clustercontents.loc['Cluster_Index'] = cc
        #df_clustercontents.loc['DatabaseNames'] = data 

        for x in range(0,10):
            print_values(x)

I need the values "cc" and "data" to be appended to the dataframe incrementally.

Any help would be really appreciated !!

piRSquared
  • 265,629
  • 48
  • 427
  • 571
user3447653
  • 3,386
  • 9
  • 50
  • 83
  • Possible duplicate of [add one row in a pandas.DataFrame](http://stackoverflow.com/questions/10715965/add-one-row-in-a-pandas-dataframe) – Zeugma Feb 01 '17 at 21:01

1 Answers1

0

You can use ,

...
print(cc)
print(data)
df_clustercontents.loc[len(df_clustercontents)]=[cc,data]
...
Spandan Brahmbhatt
  • 3,276
  • 5
  • 20
  • 33