0

I want to add some columns with an funktion without typing each name for the colum like this

for i in range(0,11):
   df["row" + i] = [random.randrange(1, 50, 1) for i in range(7)]  # after the = is an exampel

thanks for you´re help

  • Does this answer your question? [Adding new column to existing DataFrame in Python pandas](https://stackoverflow.com/questions/12555323/adding-new-column-to-existing-dataframe-in-python-pandas) – ti7 Oct 19 '21 at 15:29
  • I think problem is that `i` is an int so you can't just _add_ it to a string. You either need to make sure they are both strings: `'row' + str(i)` or use `f-strings` which allow you to use the int: `f'row{i}'` when you define the column label – ALollz Oct 19 '21 at 15:30
  • thank you so much (; – Einhorn Hunter Oct 19 '21 at 15:39
  • Welcome to Stack Overflow! Please take the [tour], read [what's on-topic here](/help/on-topic), [ask], and the [question checklist](//meta.stackoverflow.com/q/260648/843953) You should clearly state your problem -- what do you expect to happen? What actually happens? Do you get an error message? If so, share the traceback. – Pranav Hosangadi Oct 19 '21 at 17:01

0 Answers0