Forums

Pandas read_csv allowing a number of different seperators

Hi All,

I am building a wep-app with Flask, which has the goal to allow people to upload a .csv file which will then be modified by my code. To do so I put the content of the .csv into a pandas df. So far everything works perfectly fine if I specify the separator precisely, such as:

df = pd.read_csv(filename, sep=";")

In the meantime I have come to realize that Europe uses a ";" as separator, while in the US a "," is used. So I want to modify my code in a way that both kind of .csv files can be read. I modiefied my code as follows:

df = pd.read_csv(filename, sep=None, engine="python")

This works if I run it locally in the Python Shell on my computer, but doesnt work in pythonanywhere. Does anyone know how to fix this problem and how to make the code run again, allowing both kinds of input to be processed?

Thanks a lot!

Martin

Are you sure you're using the same version on Pandas in both cases? You can use the pip show command to check -- for example, if you are running your website using Python 3.7, you can run:

pip3.7 show pandas

...in a bash console to see which version is being picked up on PythonAnywhere. If you're using a virtualenv, instead you should use the "Start a bash console in this virtualenv" link on the "Web" page to start bash and then just

pip show pandas

The exact command you would use on your local machine depends on how you've installed Python and pip, but will be similar.

If the versions differ, you can use pip install to install a specific version. For example, for Python 3.7 without a virtualenv, you would install version 1.2.3 like this:

pip3.7 install --user pandas==1.2.3

...or with a virtualenv, just

pip install pandas==1.2.3

Hi, realise this is old post but having trouble installing pandas 1.2.3. I'm using the command: pip3.7 install --user pandas==1.2.3

but I get the following:

    Could not find a version that satisfies the requirement pandas==1.2.3 (from versions: 0.1, 0.2, 0.3.0, 0.4.0, 0.4.1, 0.4.2, 0.4.3, 0.5.0, 0.6.0, 0.6.1, 0
.7.0, 0.7.1, 0.7.2, 0.7.3, 0.8.0, 0.8.1, 0.9.0, 0.9.1, 0.10.0, 0.10.1, 0.11.0, 0.12.0, 0.13.0, 0.13.1, 0.14.0, 0.14.1, 0.15.0, 0.15.1, 0.15.2, 0.16.0, 0.16
.1, 0.16.2, 0.17.0, 0.17.1, 0.18.0, 0.18.1, 0.19.0, 0.19.1, 0.19.2, 0.20.0, 0.20.1, 0.20.2, 0.20.3, 0.21.0, 0.21.1, 0.22.0, 0.23.0, 0.23.1, 0.23.2, 0.23.3,
 0.23.4, 0.24.0, 0.24.1, 0.24.2, 0.25.0, 0.25.1, 0.25.2, 0.25.3, 1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.1.0, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.1.5)
No matching distribution found for pandas==1.2.3

any thoughts? I need this to install openai so keep to find a solution

You're using a quite old system image -- Python 3.7 there supports pandas up to v. 1.1.5. You can upgrade your system image, see: https://help.pythonanywhere.com/pages/ChangingSystemImage/.