mirror of
https://github.com/jbranchaud/til
synced 2026-01-06 16:48:01 +00:00
Add Create A Dummy DataFrame In Pandas as a python til
This commit is contained in:
@@ -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
|
||||
|
||||
24
python/create-a-dummy-dataframe-in-pandas.md
Normal file
24
python/create-a-dummy-dataframe-in-pandas.md
Normal file
@@ -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`.
|
||||
Reference in New Issue
Block a user