Skip to content

Instantly share code, notes, and snippets.

@mprzybyla123
Created May 12, 2020 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mprzybyla123/d3a298a8598c2c653c14c87ba20ed236 to your computer and use it in GitHub Desktop.
Save mprzybyla123/d3a298a8598c2c653c14c87ba20ed236 to your computer and use it in GitHub Desktop.
pandas-append
# All the python code below for use:
# import library
import pandas as pd
# read in your dataframe
df = pd.read_csv('/Users/data.csv')
# print out your first five rows
df.head()
# write out new rows
rows = [pd.Series([200, 200, 30,'Yellow','Label_1'], index=df.columns),
pd.Series([200, 120, 40,'Red','Label_2'], index=df.columns),
pd.Series([120, 40, 200,'Red','Label_3'], index=df.columns)]
# append the multiple rows
new_df = df.append(rows, ignore_index=True)
# check the newest 3 rows you made
new_df.tail(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment