Advertisement
elena1234

add new rows in dataframe in Pythom

Mar 4th, 2023 (edited)
859
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | Source Code | 0 0
  1. df.loc[5,:] = ['Sergio Ramus', 'Spain', 'Real Madrid', True, 1.84, 5] # add one row at the end
  2.  
  3. new_df = pd.DataFrame(
  4.          data = [['Sergio Ramus', 'Spain', 'Real Madrid', True, 1.84, 5],
  5.                  ['Van Nistelroy', 'Spain', 'Real Madrid', True, 1.70, 5]]
  6.          columns = df.columns
  7. ) # create new dataframe with many rows
  8.  
  9. df = df.append(new_df, ignore_index = True) # append the new dataframe into previous dataframe
  10.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement