Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

read a csv file in 3 columns

I want to read a csv file with 3 columns: "source","target","genre_ids" with python

df = pd.read_csv('edges1.csv',encoding="ISO-8859-1",  delimiter=';;', header=None,skiprows=1, names=columns,engine="python",index_col=False )
data = pd.concat([df.iloc[:,0].str.split(',', expand=True).rename(columns:=['source','target','genre_ids']), axis==1])

I want to get:

source          target    genre_ids
apple           green      21
strawberry       red       23
son on

edge1.csv contains:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

source,target,genre_ids
apple,green,21
strawberry,red,23
and so on

when I read the edges1.csv file I have data on only one column. To separate the columns I found the concat method online which splits the columns, but it doesn’t work.

>Solution :

From the sample data, it seems the delimiter is ,, but in your code you’re explicitly setting it to ;;. Using the correct delimiter should solve the problem:

df = pd.read_csv('edges1.csv', encoding="ISO-8859-1",  delimiter=',', header=None, skiprows=1, names=columns,e ngine="python", index_col=False )
# Here -----------------------------------------------------------^
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading