Skip to content

Instantly share code, notes, and snippets.

@gchavez2
Last active August 20, 2019 18:43
Show Gist options
  • Save gchavez2/b8f4d798ff9f47ec60ea88fbae8aae2a to your computer and use it in GitHub Desktop.
Save gchavez2/b8f4d798ff9f47ec60ea88fbae8aae2a to your computer and use it in GitHub Desktop.
nme = ["aparna", "pankaj", "sudhir", "Geeku"]
deg = ["MBA", "BCA", "M.Tech", "MBA"]
scr = [90, 40, 80, 98]
# New from dictionary
dict = {'name': nme, 'degree': deg, 'score': scr}
df = pd.DataFrame(dict)
clean_df.to_csv(OUTPUT_FILENAME, index=False)
# New dataframe from subset of pandas dataframe
clean_df = df.loc[idx_list]
clean_df.to_csv(OUTPUT_FILENAME, index=False)
# New from head
OUTPUT_FILENAME='./smaller_df.csv'
ndf = df.head()
ndf.to_csv(OUTPUT_FILENAME, sep=',', encoding='utf-8', index=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment