# Probleme Reading csv column , Python dont recognize column even its right spelling

**URL:** https://discourse.jupyter.org/t/probleme-reading-csv-column-python-dont-recognize-column-even-its-right-spelling/29243
**Category:** ipynb
**Tags:** jupyterlab, notebook
**Created:** [October 15, 2024, 11:28am UTC](https://discourse.jupyter.org/t/probleme-reading-csv-column-python-dont-recognize-column-even-its-right-spelling/29243 "2024-10-15T11:28:17Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![amine59](https://avatars.discourse-cdn.com/v4/letter/a/50afbb/32.png) [@amine59](https://discourse.jupyter.org/u/amine59)
#### Post date: [October 15, 2024, 11:28am UTC](https://discourse.jupyter.org/t/probleme-reading-csv-column-python-dont-recognize-column-even-its-right-spelling/29243/1 "2024-10-15T11:28:17Z")

</div>

Hello Jupyeter community

I have a probleme with reading column , When i want to make calculation , even all things is right, the speling name in script is the same as in my csv file, VS code dont read the coulmn name even its speling 100% correct and send all times Error, please help me

1. Élément

def classify\_return(Investment\_Return):  
if Investment\_Return\> good\_return\_threshold:  
return’Good’  
else:  
return’Not good’

This code is correct:

1. Élément

Then i write :

mutual\_funds[‘Return\_Classification’]= mutual\_funds[‘Investment\_Return’].apply(classify\_return)

Error is this : KeyError: ‘Investment\_Return’

The above exception was the direct cause of the following exception:

---

<div class="post-metadata">

### Author: ![fomightez](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/fomightez/32/495_2.png) [@fomightez](https://discourse.jupyter.org/u/fomightez)
#### Post date: [October 15, 2024, 12:24pm UTC](https://discourse.jupyter.org/t/probleme-reading-csv-column-python-dont-recognize-column-even-its-right-spelling/29243/2 "2024-10-15T12:24:11Z")

</div>

Please, consider if this is pertinent to this forum about Jupyter? If you ran this Python code in a more traditional way, such as in the console or as the content a script you called from the command line for Python run, would it give the same outcome? (If you are new to running Python code, you may not be able to do this exercise in your mind, and should actually step through the exercise.) If so, it isn’t a Jupyter issue and so not pertinent to this forum. You’ll want to seek help in a pertinent location.

* * *

Your provided code is unuseable and nearly unreadable.

For pasting code in so it is readable in forums such as this & useable by those you want to help you, you’ll want to learn about ‘block code formatting’ [here](https://meta.discourse.org/t/post-code-or-preformatted-text/188910#block-code-formatting-6). (Or see about ‘fenced code blocks’ [here](https://meta.stackoverflow.com/a/251362/8508004). They are both the same thing if you look into the details. They just have slightly different terms used in the two locations.

---

<div class="post-metadata">

### Author: ![amine59](https://avatars.discourse-cdn.com/v4/letter/a/50afbb/32.png) [@amine59](https://discourse.jupyter.org/u/amine59)
#### Post date: [October 15, 2024, 12:41pm UTC](https://discourse.jupyter.org/t/probleme-reading-csv-column-python-dont-recognize-column-even-its-right-spelling/29243/3 "2024-10-15T12:41:28Z")

</div>

Sr , Im not beguinner , i run c,c++ since 2018 and all what i want is to get answer not somethings innapropriate like your message , Sr i want answer about coulmn not reading in script or maybe you are not able to help me and in this case let another one get help to me

---

<div class="post-metadata">

### Author: ![fomightez](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/fomightez/32/495_2.png) [@fomightez](https://discourse.jupyter.org/u/fomightez)
#### Post date: [October 15, 2024, 2:22pm UTC](https://discourse.jupyter.org/t/probleme-reading-csv-column-python-dont-recognize-column-even-its-right-spelling/29243/4 "2024-10-15T14:22:02Z")

</div>

Please read [Getting good answers to your questions](https://discourse.jupyter.org/t/getting-good-answers-to-your-questions/1825). I would suggest paying particular attention to the section ‘Help others reproduce the problem’, in the link to [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask) at the bottom there.

* * *

Your code and issue is not reproducible as provided.  
Here is a minimal, toy example adapted from **the incomplete code you provided** :

```python
import pandas as pd
mutual_funds = pd.DataFrame({'A': range(1, 6),
                   'B': range(10, 0, -2),
                   'Investment_Return': range(100, 0, -20),
                   'C C': range(10, 5, -1)})

good_return_threshold = 51
def classify_return(Investment_Return):
    if Investment_Return> good_return_threshold:
        return 'Good'
    else:
        return 'Not good'
mutual_funds['Return_Classification']= mutual_funds['Investment_Return'].apply(classify_return)

```

(Notice the code is formatted to be pasteable.).  
This code works fine, as can be observed by clicking [here](https://mybinder.org/v2/gist/fomightez/cd4b8a3e4e7a74bcd01b6519115ede2c/HEAD?labpath=Jupyter_Discourse_forum_29243_test.ipynb) and running it when the session starts. (Or click [here](https://fomightez.github.io/jupyterlite-xeus-demo/lab/?path=Jupyter_Discourse_forum_29243_test.ipynb) if you want it in JupyterLite, which is **a nice option when MyBinder-served sessions are being slow to come up**.) ([Here](https://nbviewer.org/urls/gist.githubusercontent.com/fomightez/cd4b8a3e4e7a74bcd01b6519115ede2c/raw/46fd43f5e9052878ea8d1f3ca0a6f9c779f33fb1/Jupyter_Discourse_forum_29243_test.ipynb) is the boring static view, but the two links prior are much more useful and I suggest using those primarily.)

In other words, I don’t see your reported issue with the limited code and information provided.  
If however, I change the equivalent line you had an issue with to `mutual_funds['Return_Classification']= mutual_funds['Z'].apply(classify_return)`, then I get `KeyError: 'Z'` because there is no column named `Z` in my dataframe.

---

<div class="post-metadata">

### Author: ![amine59](https://avatars.discourse-cdn.com/v4/letter/a/50afbb/32.png) [@amine59](https://discourse.jupyter.org/u/amine59)
#### Post date: [October 15, 2024, 3:49pm UTC](https://discourse.jupyter.org/t/probleme-reading-csv-column-python-dont-recognize-column-even-its-right-spelling/29243/6 "2024-10-15T15:49:37Z")

</div>

Hello Sr thanks you for your Reply ,

its sems your know well code. And instructed person,

Otherwise . You will help me more if you tell me Whats IS the issue with m’y script, file that i load. Because the name of the column is mentioned correcltly in the script.

Error: python dont detect coulmn with name “Investment\_Return”

---

<div class="post-metadata">

### Author: ![fomightez](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/fomightez/32/495_2.png) [@fomightez](https://discourse.jupyter.org/u/fomightez)
#### Post date: [October 15, 2024, 3:58pm UTC](https://discourse.jupyter.org/t/probleme-reading-csv-column-python-dont-recognize-column-even-its-right-spelling/29243/7 "2024-10-15T15:58:06Z")

</div>

**If you read through everything already written above and follow it** , you’d see you’d need to provide more details for anyone to be able to help you.

Did you run `mutual_funds.columns` before you ran your line `mutual_funds[‘Return_Classification’]= mutual_funds[‘Investment_Return’].apply(classify_return)`? What was the result?  
Is there a column named `Investment_Return`?

When I run `mutual_funds.columns` at the equivalent point in my demonstration notebook, I see the following

```python
Index(['A', 'B', 'Investment_Return', 'C C'], dtype='object')`

```

And thus I am sure there is a column named that before I run, `mutual_funds['Return_Classification']= mutual_funds['Investment_Return'].apply(classify_return)`.

---

<div class="post-metadata">

### Author: ![amine59](https://avatars.discourse-cdn.com/v4/letter/a/50afbb/32.png) [@amine59](https://discourse.jupyter.org/u/amine59)
#### Post date: [October 15, 2024, 4:28pm UTC](https://discourse.jupyter.org/t/probleme-reading-csv-column-python-dont-recognize-column-even-its-right-spelling/29243/8 "2024-10-15T16:28:59Z")

</div>

#JupyterLab This is my code

1. Élément

import numpy as np

import pandas as pd

1. Élément  
#step 1 load data from excel file  
mutual\_funds=pd.read\_csv(‘mutual\_funds.csv’) ✅

2. Élément  
mutual\_funds.head()  
||Fund Name;Investment\_Amount;Current\_Value;Investment\_Return;Return\_Classification;Date\_Invested|  
|—|—|  
|0|Fund A;1000;1200;0.2;Good;01/01/2023|  
|1|Fund B;1500;1300;-0.1333;Not good;01/02/2023|  
|2|Fund C;2000;2500;0.25;Good;01/03/2023|  
|3|| ✅

3. Élément  
#calassify investement return  
def classify\_return(Investment\_Return):  
if Investment\_Return\> good\_return\_threshold:  
return’Good’  
else:  
return’Not good’ ✅

4. Élément  
#Apply the classification to the dataframe

mutual\_funds[‘Return\_Classification’]= mutual\_funds[‘Investment\_Return’].apply(classify\_return)  
😣 ❌  
Error : ‘Investment\_Return’ Not exist

---

<div class="post-metadata">

### Author: ![fomightez](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/fomightez/32/495_2.png) [@fomightez](https://discourse.jupyter.org/u/fomightez)
#### Post date: [October 15, 2024, 5:11pm UTC](https://discourse.jupyter.org/t/probleme-reading-csv-column-python-dont-recognize-column-even-its-right-spelling/29243/9 "2024-10-15T17:11:46Z")

</div>

This is still not complete, addressing my last questions, or formatted than anyone can use it. See my examples above and follow them using advice about ‘fenced code blocks’.

Why do I say this is not complete:  
Where is `good_return_threshold` set?

Why do I say it doesn’t address what I asked:  
You still didn’t run `mutual_funds.columns` before you ran your code that isn’t working and provide the result.  
I’d also suggest you run `len(mutual_funds.columns)` and compare that result to what you expect.  
If you parsed your CSV file correctly, how many columns do you expect?

It seems to me you either didn’t share the result of `mutual_funds.head()` well in text or you didn’t parse the CSV correctly. If the latter option is the case then it means **there shouldn’t be a green check mark for step 3.** That being the case seems likely, since you have after running `mutual_funds.head()` the following:

```plaintext
|—|—|

```

Meaning there may only be the Row Indexes and a single column. Hence, there is no column `Investment_Return`, **like the error keeps telling you**.  
But of course, maybe you just didn’t share the result of `mutual_funds.head()` well in text?
