diff --git a/README.md b/README.md index a569a12..0522721 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ and pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud). -_916 TILs and counting..._ +_917 TILs and counting..._ --- @@ -521,6 +521,7 @@ _916 TILs and counting..._ ### Python - [Access Instance Variables](python/access-instance-variables.md) +- [Create A Dummy DataFrame In Pandas](python/create-a-dummy-dataframe-in-pandas.md) - [Test A Function With Pytest](python/test-a-function-with-pytest.md) ### Rails diff --git a/python/create-a-dummy-dataframe-in-pandas.md b/python/create-a-dummy-dataframe-in-pandas.md new file mode 100644 index 0000000..22f618d --- /dev/null +++ b/python/create-a-dummy-dataframe-in-pandas.md @@ -0,0 +1,24 @@ +# Create A Dummy DataFrame In Pandas + +[Pandas](https://pandas.pydata.org/pandas-docs/stable/index.html) has all kinds +of utilities for pulling in and processing tabular data. You can pull in a +bunch of data from a SQL database into a `DataFrame`. This `DataFrame` object +is then something you could pass around, process, and read from. + +When you are sketching out an implementation or writing some tests, it may not +be feasible to read data from a DB. Instead, you can create a little dummy +`DataFrame` using the +[`from_dict`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.from_dict.html#pandas.DataFrame.from_dict) +function. + + +```python +import pd + +data = {'pokemon': ['Charmander', 'Squirtle', 'Bulbasaur'], 'type': ['Fire', 'Water', 'Grass']} +pd.DataFrame.from_dict(data) +``` + +This creates a two column `DataFrame` with a `pokemon` header and a `type` +header. The two lists of value will be matched up positionally, so `squirtle` +will be paired with `water`.