Skip to content

Instantly share code, notes, and snippets.

@mberrien-fitzsimons
Last active August 21, 2019 16:04
Show Gist options
  • Save mberrien-fitzsimons/175c66a756ebafd0ce2413dcdc6db06f to your computer and use it in GitHub Desktop.
Save mberrien-fitzsimons/175c66a756ebafd0ce2413dcdc6db06f to your computer and use it in GitHub Desktop.
import pandas as pd
import numpy as np
def create_empty_dataframe(new_column_list, num_rows):
"""
Creates a new dataframe filled with zeroes from a specified
list and number of rows.
Args:
new_col_list (object): List of column names.
num_rows (int): Number of rows you want the new table to have.
Returns:
df: returns a pandas dataframe with specific column
names and number of rows.
"""
col_list = new_column_list
num_cols = len(new_column_list)
fill_with_zeroes = np.zeros(shape=(num_rows, num_cols))
new_df = pd.DataFrame(fill_with_zeroes, columns=[col_list])
return new_df
import pytest
from mypackage_two.pandas_math import create_empty_dataframe
class TestCreateEmptyDataframe(object):
def test_on_create_empty_dataframe(self):
actual = len(create_empty_dataframe(['foo', 'bar'], 20))
expected = 20
assert actual == expected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment