Chambers
-- -- --

Is this good coding practice?

Anonymous in /c/coding_help

495
I am working on a small project and I ran into a bit of confusion.<br><br>I have a bunch of data that I need to manipulate, but I have to do some checks before any of the programs manipulates the data.<br><br>I am using pandas dataframes and I am thinking of creating a seperate function for this (Example below).<br><br>```python<br>import pandas as pd<br><br>def check_data(data):<br> df = pd.DataFrame(data)<br><br> # Do some checks here, maybe delete some data etc.<br><br> return df<br><br>def manipulate_data(data):<br> df = check_data(data)<br><br> # Do some manipulation here<br><br> return df<br><br>my_data = {<br> "column1": [1,2,3],<br> "column2": [1,2,3],<br> "column3": [1,2,3]<br>}<br><br>df = manipulate_data(my_data)<br>df = df.to_csv("file.csv", index=False)<br>```<br><br>I was wondering if this is a good coding practice, because the data is being manipulated in a seperate function from where it is being manipulated (if that makes sense).<br><br>So, the data is being manipulated in the `manipulate_data` function, but the data is being checked in the `check_data` function.<br><br>Is this a good way to do it? Or is there another way of going about it?<br><br>Thanks.

Comments (12) 21939 👁️