AOJ keygen
AOJ keygen

Reputation: 103

How to create pandas dataframe inside QGIS from the imported csv?

I have a road database with long/latitude loaded into QGIS, and I also have prepared my python code in Jupyter Notebook for some calculation. I was asked to put my code that works totally separately from QGIS into QGIS so that other people who have no idea about python can work with it.

I've tried update the python console in qgis with my anacoda package so now my qgis has some important library such as pandas which is crucial for my code.

The problem is that qgis shutdown itself every time when I tried to read csv data to be df(just basic df=pd.read_csv). It does not happen with a simple dataframe (a 2 by 3 df filled with random numbers ). What is the better way to read scv as df in QGIS?

Upvotes: 2

Views: 1229

Answers (1)

Max
Max

Reputation: 93

Try different approaches. Read the csv with

from numpy import genfromtxt 
my_data = genfromtxt('my_file.csv', delimiter=',')

then transform it with pandas

df = pandas.DataFrame(data=my_data)

Upvotes: 1

Related Questions