0

code: df_t["My address"]=["My address",7,"My city","My State","My Country","My Shop",12,"My Continent"]

ValueError: Length of values (8) does not match length of index (7)

  • table: ID City State Country Supermarket Name Number of Employees Continent Address 3666 21st st 1 San Francisco CA94114 USA Madeira 8 USA,North America 735 Dolores St 2 San Francisco CA 94119 USA Bready Shop 15 USA,North America 332 Hill St 3 San Francisco California 94114 USA Super River 25 USA,North America 3995 23rd St 4 San Francisco CA 94114 USA Ben's Shop 10 USA,North America 1056 Sanchez St 5 San Francisco California USA Sanchez 12 USA,North America 551 Alvarado St 6 San Francisco CA 94114 USA Richvalley 20 USA,North America – Monoare Hossain Jul 20 '22 at 10:43

1 Answers1

0

Your code tries to add a new column, not a row. If you want to actually add a row to your DataFrame you have several options, one of many being:

df_t.loc[len(df_t)] = ["My address",7,"My city","My State","My Country","My Shop",12,"My Continent"]

However, please notice that growing a DataFrane by adding new rows isn't a best practice (see this very explanatory reference).

Next time please add your sample dataframe directly in the question and not in the comments (you can also edit your question)

Alessandro
  • 361
  • 1
  • 9