Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help on String variable
#3
Thanks Yoriz for prompt help.

Actually data is in csv file came from more than 5000 respondents. one of the variable is method_discussed having more than 5000 data points and these data points may be of any/all combination of items from dictionary
method_names = ['female_condoms', 'emergency', 'male_condoms', 'pill', 'injectables', 'iud', 'male_sterilization', 'female_sterilization'].
For eaxample

rspondent method_discussed
respondent1 female_condoms injectables
respondent2 male_sterilization pill
respondent3 blank (no method)
.
.
.
so on
respondent5000 male_sterilization female_sterilization
.
.

I imported pandas as pd read the csv file and made a dictionary of these 8 methods. I want to generate 8 variables based on name of these 8 items in dictionary whose data points are 0 (absence of particular item in method_discussed) and 1 (presence of particular item in method_discussed), as you have done but not in memory but in same csv file and save it.

I dont want these results in memory as you have done bit in dataframe. Second thing I want to bring in your notice that I dont want to assign method_discuused as you have done for only 5 cases

methods_discussed = [['iud', 'male_condoms', 'pill'],
['male_condoms'],
[],
['female_sterilization', 'male_sterilization'],
['male_sterilization', 'iud', 'injectables']]

as I said it has more than 5000 cases (data points), in other words, method_discussed take any combination of items from dictionary above.

If you need I can send the csv file with expected outcome in EXCEL.

Thanks

Ashish
Reply


Messages In This Thread
Help on String variable - by ashishstats - Aug-04-2019, 11:19 AM
RE: Help on String variable - by Yoriz - Aug-04-2019, 12:34 PM
RE: Help on String variable - by ashishstats - Aug-05-2019, 09:39 AM
RE: Help on String variable - by ashishstats - Aug-13-2019, 08:58 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Replacing String Variable with a new String Name kevv11 2 932 Jul-29-2023, 12:03 PM
Last Post: snippsat
  Need help on how to include single quotes on data of variable string hani_hms 5 2,457 Jan-10-2023, 11:26 AM
Last Post: codinglearner
  python r string for variable mg24 3 3,329 Oct-28-2022, 04:19 AM
Last Post: deanhystad
  USE string data as a variable NAME rokorps 1 1,078 Sep-30-2022, 01:08 PM
Last Post: deanhystad
  Removing Space between variable and string in Python coder_sw99 6 6,644 Aug-23-2022, 01:15 PM
Last Post: louries
  Remove a space between a string and variable in print sie 5 2,006 Jul-27-2022, 02:36 PM
Last Post: deanhystad
  Split string using variable found in a list japo85 2 1,454 Jul-11-2022, 08:52 AM
Last Post: japo85
  Can you print a string variable to printer hammer 2 2,139 Apr-30-2022, 11:48 PM
Last Post: hammer
Question How to convert string to variable? chatguy 5 2,853 Apr-12-2022, 08:31 PM
Last Post: buran
  I want to search a variable for a string D90 lostbit 3 2,786 Mar-31-2021, 07:14 PM
Last Post: lostbit

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020