1

Actually, I have a dataframe that contains some states and I have a list of their few cities and I want to add those cities to that dataset and want to group each city with their state names. Eg.

#I have entered some random city names for example purpose 
city = ['Akola','Aurangabad','Dhule','Jalgaon','Mumbai','Mumbai Suburban','Nagpur']

       State    Cases   Active  Recovered   Death
0   Maharashtra 77793 2933  41402 1458  33681 1352  2710 123
1   Andhra Pradesh  4223 143    1613 67 2539 73 71 3
2   Karnataka   4320 257    2653 157    1610 96 57 4
3   Goa 166 87  109 87  57  0
4   Tamil Nadu  27256 1384  12134 786   14902 586   220 12

and I want those cities to add in a data frame in a new column like

       State    Cases   Active  Recovered   Death             |CITY    
0   Maharashtra 77793 2933  41402 1458  33681 1352  2710 123  |AKOLA
1   Maharashtra 77793 2933  41402 1458  33681 1352  2710 123  |DHULE
2   Maharashtra 77793 2933  41402 1458  33681 1352  2710 123  |MUMBAI
3   Andhra Pradesh  4223 143    1613 67 2539 73 71 3          |JALGAON
4   Andhra Pradesh  4223 143    1613 67 2539 73 71 3          |NAGPUR
5   Karnataka   4320 257    2653 157    1610 96 57 4
6   Goa 166 87  109 87  57  0
7   Tamil Nadu  27256 1384  12134 786   14902 586   220 12    |AURANGABAD
8   Tamil Nadu  27256 1384  12134 786   14902 586   220 12    |MUMBAI SUBURBAN
# data is wrong so please focus in format 
Darkstar Dream
  • 1,649
  • 1
  • 12
  • 23
  • 1
    Do you have a mapping of cities to states? If not, this seems more like a question for [gis stack exchange](https://gis.stackexchange.com/help/on-topic) or for a package/module that deals with geocoding. Pandas doesn't do this. – Michael Delgado Jun 05 '20 at 06:58
  • If the mapping is available, I think this post might be of use - https://stackoverflow.com/questions/20250771/remap-values-in-pandas-column-with-a-dict – Sajan Jun 05 '20 at 06:59
  • Actually I was doing web-scraping practice and these data I got from [extracting](https://www.ndtv.com/coronavirus/india-covid-19-tracker) so, I don't have any mapping – Darkstar Dream Jun 05 '20 at 07:46
  • and also this question is not limited to `geospatial` instead of state there can be class1, class2......... etc and some may want to add student's name on their corresponding class so I am wondering how this can be solved – Darkstar Dream Jun 05 '20 at 07:58

0 Answers0