0

I am working on a column address of the csv file, which consists multiple country, city, pincode in a row of a .csv file, row data looks like this :

address
[Obaid, Shamsan S.; Gaikwad, Dhammajyot K.; Pawar, Pravina P.] Dr Babasaheb Ambedkar Marathwada Univ, Dept Phys, Aurangabad 431004, Maharashtra, India
[Kaveeshwar, Aditya Rajeev; Zappi, Mark E.; Subramaniam, Ramalingam] Univ Louisiana Lafayette, Dept Chem Engn, 218 D Madison Hall,131 Rex St,POB 42291, Lafayette, LA 70504 USA; [Ponnusamy, Senthil Kumar] SSN Coll Engn, Dept Chem Engn, Madras 603110, Tamil Nadu, India; [Revellame, Emmanuel D.] Univ Louisiana Lafayette, Dept Ind Technol, POB 43636, Lafayette, LA 70504 USA; [Gang, Daniel D.] Univ Louisiana Lafayette, Dept Civil Engn, POB 42291, Lafayette, LA 70504 USA; [Revellame, Emmanuel D.; Gang, Daniel D.; Zappi, Mark E.; Subramaniam, Ramalingam] Univ Louisiana Lafayette, Energy Inst Louisiana, POB 42291, Lafayette, LA 70504 USA

Sample dataset:

address
[Sharma,Ravi; kumar, Ram;Pandey,Neeraj]Univeristy name1,department name1,address1, pincode city1, Country1; Univeristy name2,department name2,address2, pincode city2, Country2 ; Univeristy name3,department name3,address3, pincode city3, Country3
[Oberai,Pia;Singh, Reshu] Univeristy name1,department name1,address1, pincode city1, Country1; Univeristy name2,department name2,address2, pincode city2, Country2

dataset I want as output :

Cityname1 Cityname2 Cityname3 Cityname4 Cityname5
city1 city2 city3
city city

where cityname1,2,3,4,5 are just column name

My Solution that I tried to apply for solving this is :

import pandas as pd
rawdata = pd.csv("Filepath")
newdata = pd.DataFrame(rawdata['address'].str.rsplit(",", n=3, expand=True))
newdata                            

enter image description here

tanu
  • 11
  • 2
  • 1
    Please provide the expected [MRE - Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). Show where the intermediate results deviate from the ones you expect. We should be able to paste a single block of your code into file, run it, and reproduce your problem. This also lets us test any suggestions in your context. Off-site links and images of text are not acceptable; your posting must be self-contained, in keeping with the purpose of this site. – Prune Jun 11 '21 at 05:36
  • 1
    [Include your minimal data frame](https://stackoverflow.com/questions/52413246/how-to-provide-a-reproducible-copy-of-your-dataframe-with-to-clipboard) as part of the example. – Prune Jun 11 '21 at 05:36
  • I hope @ Prune it is okay now – tanu Jun 11 '21 at 05:57
  • Don't "hope" -- follow the guidelines to which I linked you. – Prune Jun 11 '21 at 14:20
  • Now its according to the guidelines @Prune – tanu Jun 12 '21 at 11:53

0 Answers0