# Fault to access column in dataframe

**URL:** <https://discuss.python.org/t/fault-to-access-column-in-dataframe/13518>\
**Category:** Python Help\
**Tags:** help\
**Created:** [February 5, 2022, 3:31pm UTC](https://discuss.python.org/t/fault-to-access-column-in-dataframe/13518 "2022-02-05T15:31:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![krisv](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/krisv/32/6153_2.png) [@krisv](https://discuss.python.org/u/krisv)\
**Post date:** [February 5, 2022, 3:31pm UTC](https://discuss.python.org/t/fault-to-access-column-in-dataframe/13518/1 "2022-02-05T15:31:32Z")

</div>

Hi, can someone help me, i search to find code to access the value of column3 in a dataframe, when this value is \<= 0, then write these to a textfile.  
I have a dataframe with 4 columns and 1000 rows, all are integer except column with index 3, is float and is used for currency (example: 2022,01,123456,23.25), this value can be zero or negative and want these row writing to another txt file.

my code:  
data2 = pd.to\_csv(dataOUT, dataIN[column(3)], fmt=fFiles).

What’s wrong?  
Is there a lambda function for this?  
Thanks in advance for your helping brains.

---

<div class="post-metadata">

**Author:** ![Mholscher](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/mholscher/32/15325_2.png) [@Mholscher](https://discuss.python.org/u/Mholscher)\
**Post date:** [February 6, 2022, 10:42pm UTC](https://discuss.python.org/t/fault-to-access-column-in-dataframe/13518/2 "2022-02-06T22:42:55Z")

</div>

The pandas documentation shows the following format for to\_csv:  
`DataFrame.to_csv( *path_or_buf=None* , *sep=','* , *na_rep=''* , *float_format=None* , *columns=None* , *header=True* , *index=True* , *index_label=None* , *mode='w'* , *encoding=None* , *compression='infer'* , *quoting=None* , *quotechar='"'* , *line_terminator=None* , *chunksize=None* , *date_format=None* , *doublequote=True* , *escapechar=None* , *decimal='.'* , *errors='strict'* , *storage_options=None* )`

This does not map to your use of the method. `dataOUT` should contain a file path, be a file-like structure or `None`.

`dataIN[column(3)]` should contain a separator, that seems really improbable if not impossible. Use the `column=` keyword to select columns. I could not find any example to select columns based on number and I have never done that. Maybe you have to name your columns, so you can select on label here.

There is no argument with key `fmt`, I don’t know what you think that will do.

---

<div class="post-metadata">

**Author:** ![krisv](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/krisv/32/6153_2.png) [@krisv](https://discuss.python.org/u/krisv)\
**Post date:** [February 7, 2022, 10:37am UTC](https://discuss.python.org/t/fault-to-access-column-in-dataframe/13518/3 "2022-02-07T10:37:08Z")

</div>

I found the solution to use the option dataframe(mask)

def mask():  
fFile = ‘%i’,’%i’,’%i’,’%1.2f’  
dataOUT = Path(…)  
df = pd.DataFrame(dataIN, columns=[‘Jaar’,‘Maand’,‘BadgeNr’,‘Bedrag’])  
mask = df[‘Bedrag’].values \<= 0  
n = df[mask]  
np.savetxt(dataOUT, n, delimiter=’;’, fmt=fFile, header=“Foutieve Input”)

4 2020 7 47015 29.70  
… … … … …  
1087 2020 7 30536 41.65  
1088 2020 7 8453 19.40  
1089 2020 7 3901 11.85  
1090 2020 7 36117 6.95  
1091 2020 7 46814 2.80

[1092 rows x 4 columns] found

Result after reading file of 1092 rows

```
 Jaar Maand BadgeNr Bedrag

```

134 2020 7 38245 0.0
