Python-c04-indexes

1
import pandas as pd
1
2
df = pd.read_csv('data/survey_results_public.csv',  index_col='Respondent')
df_schema = pd.read_csv('data/survey_results_schema.csv', index_col='Column')
1
2
# inplace=True will apply the changes to the DataFrame
df_schema.sort_index(inplace=True)
1
df_schema

Question
Column
AnnoyingUI It annoys me when software has a poor UI
AssessJobCommute When you're assessing potential jobs to apply ...
AssessJobCompensation When you're assessing potential jobs to apply ...
AssessJobDept When you're assessing potential jobs to apply ...
AssessJobDiversity When you're assessing potential jobs to apply ...
... ...
WorkPayCare I don't really care what I work on, so long as...
WorkStart Suppose you could choose your own working hour...
YearsCodedJob For how many years have you coded as part of y...
YearsCodedJobPast For how many years did you code as part of you...
YearsProgram How long has it been since you first learned h...

154 rows × 1 columns

1
2
# set index to the Country
df.set_index('Country', inplace=True)
1
2
# give the list of index elements
df.index

Index([‘United States’, ‘United Kingdom’, ‘United Kingdom’, ‘United States’,
‘Switzerland’, ‘New Zealand’, ‘United States’, ‘Poland’, ‘Colombia’,
‘France’,

‘United States’, ‘India’, ‘United Kingdom’, ‘United States’, ‘France’,
‘Canada’, ‘India’, ‘United Kingdom’, ‘United States’, ‘France’],
dtype=’object’, name=’Country’, length=19102)

1
2
# pass the element of the index to loc
df.loc['United States']

University EmploymentStatus FormalEducation MajorUndergrad HomeRemote CompanySize CompanyType YearsProgram YearsCodedJob YearsCodedJobPast ... StackOverflowMakeMoney Gender HighestEducationParents Race SurveyLong QuestionsInteresting QuestionsConfusing InterestedAnswers Salary ExpectedSalary
Country
United States No Not employed, and not looking for work Secondary school NaN NaN NaN NaN 2 to 3 years NaN NaN ... Strongly disagree Male High school White or of European descent Strongly disagree Strongly agree Disagree Strongly agree NaN NaN
United States No Employed full-time Doctoral degree A non-computer-focused engineering discipline Less than half the time, but at least one day ... 10,000 or more employees Non-profit/non-governmental organization or pr... 14 to 15 years 9 to 10 years NaN ... Disagree Male A doctoral degree White or of European descent Agree Agree Somewhat agree Strongly agree NaN NaN
United States No Employed full-time Master's degree A non-computer-focused engineering discipline Less than half the time, but at least one day ... 20 to 99 employees Government agency or public school/university 9 to 10 years 8 to 9 years NaN ... Disagree Male A doctoral degree White or of European descent Disagree Agree Disagree Agree NaN NaN
United States No Employed full-time Bachelor's degree A social science All or almost all the time (I'm full-time remote) 100 to 499 employees Venture-funded startup 12 to 13 years 11 to 12 years NaN ... Strongly disagree Female Some college/university study, no bachelor's d... White or of European descent Strongly disagree Agree Strongly disagree Strongly agree NaN NaN
United States Yes, part-time Independent contractor, freelancer, or self-em... Primary/elementary school NaN All or almost all the time (I'm full-time remote) NaN NaN 11 to 12 years 1 to 2 years NaN ... Disagree Male A doctoral degree White or of European descent Disagree Somewhat agree Strongly disagree Agree NaN NaN
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
United States No Employed full-time Bachelor's degree A natural science All or almost all the time (I'm full-time remote) Fewer than 10 employees Privately-held limited company, not in startup... 6 to 7 years 3 to 4 years NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
United States No Employed part-time Some college/university study without earning ... Computer science or software engineering Less than half the time, but at least one day ... 10 to 19 employees Sole proprietorship or partnership, not in sta... 2 to 3 years 1 to 2 years NaN ... NaN Male Some college/university study, no bachelor's d... White or of European descent Disagree Agree Disagree Strongly agree NaN NaN
United States No Employed full-time Bachelor's degree Management information systems Never 10,000 or more employees Publicly-traded corporation 20 or more years 20 or more years NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
United States No Employed full-time Bachelor's degree Computer science or software engineering A few days each month 100 to 499 employees Venture-funded startup 20 or more years 19 to 20 years NaN ... Disagree Male A bachelor's degree White or of European descent Somewhat agree Somewhat agree Disagree Somewhat agree NaN NaN
United States No Employed full-time Some college/university study without earning ... A humanities discipline Less than half the time, but at least one day ... 100 to 499 employees Sole proprietorship or partnership, not in sta... 20 or more years 20 or more years NaN ... Disagree Male Some college/university study, no bachelor's d... White or of European descent Somewhat agree Somewhat agree Disagree Agree 110000.0 NaN

4364 rows × 150 columns

1
2
# reset the index to the integer
df.reset_index(inplace=True)
1
df

Country University EmploymentStatus FormalEducation MajorUndergrad HomeRemote CompanySize CompanyType YearsProgram YearsCodedJob ... StackOverflowMakeMoney Gender HighestEducationParents Race SurveyLong QuestionsInteresting QuestionsConfusing InterestedAnswers Salary ExpectedSalary
0 United States No Not employed, and not looking for work Secondary school NaN NaN NaN NaN 2 to 3 years NaN ... Strongly disagree Male High school White or of European descent Strongly disagree Strongly agree Disagree Strongly agree NaN NaN
1 United Kingdom Yes, full-time Employed part-time Some college/university study without earning ... Computer science or software engineering More than half, but not all, the time 20 to 99 employees Privately-held limited company, not in startup... 9 to 10 years NaN ... Strongly disagree Male A master's degree White or of European descent Somewhat agree Somewhat agree Disagree Strongly agree NaN 37500.0
2 United Kingdom No Employed full-time Bachelor's degree Computer science or software engineering Less than half the time, but at least one day ... 10,000 or more employees Publicly-traded corporation 20 or more years 20 or more years ... Disagree Male A professional degree White or of European descent Somewhat agree Agree Disagree Agree 113750.0 NaN
3 United States No Employed full-time Doctoral degree A non-computer-focused engineering discipline Less than half the time, but at least one day ... 10,000 or more employees Non-profit/non-governmental organization or pr... 14 to 15 years 9 to 10 years ... Disagree Male A doctoral degree White or of European descent Agree Agree Somewhat agree Strongly agree NaN NaN
4 Switzerland No Employed full-time Master's degree Computer science or software engineering Never 10 to 19 employees Privately-held limited company, not in startup... 20 or more years 10 to 11 years ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
19097 Canada No Employed full-time Bachelor's degree A business discipline A few days each month 10 to 19 employees Privately-held limited company, not in startup... 1 to 2 years 1 to 2 years ... Disagree Male Some college/university study, no bachelor's d... White or of European descent Somewhat agree Agree Disagree Agree NaN NaN
19098 India No Not employed, and not looking for work Secondary school NaN NaN NaN NaN 1 to 2 years NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
19099 United Kingdom No Independent contractor, freelancer, or self-em... Bachelor's degree Computer science or software engineering Never NaN NaN 14 to 15 years 14 to 15 years ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
19100 United States No Employed full-time Some college/university study without earning ... A humanities discipline Less than half the time, but at least one day ... 100 to 499 employees Sole proprietorship or partnership, not in sta... 20 or more years 20 or more years ... Disagree Male Some college/university study, no bachelor's d... White or of European descent Somewhat agree Somewhat agree Disagree Agree 110000.0 NaN
19101 France No Employed full-time Master's degree Computer science or software engineering All or almost all the time (I'm full-time remote) 100 to 499 employees Sole proprietorship or partnership, not in sta... 14 to 15 years 9 to 10 years ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN

19102 rows × 151 columns

1
df.sort_index(ascending=False)

Country University EmploymentStatus FormalEducation MajorUndergrad HomeRemote CompanySize CompanyType YearsProgram YearsCodedJob ... StackOverflowMakeMoney Gender HighestEducationParents Race SurveyLong QuestionsInteresting QuestionsConfusing InterestedAnswers Salary ExpectedSalary
19101 France No Employed full-time Master's degree Computer science or software engineering All or almost all the time (I'm full-time remote) 100 to 499 employees Sole proprietorship or partnership, not in sta... 14 to 15 years 9 to 10 years ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
19100 United States No Employed full-time Some college/university study without earning ... A humanities discipline Less than half the time, but at least one day ... 100 to 499 employees Sole proprietorship or partnership, not in sta... 20 or more years 20 or more years ... Disagree Male Some college/university study, no bachelor's d... White or of European descent Somewhat agree Somewhat agree Disagree Agree 110000.0 NaN
19099 United Kingdom No Independent contractor, freelancer, or self-em... Bachelor's degree Computer science or software engineering Never NaN NaN 14 to 15 years 14 to 15 years ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
19098 India No Not employed, and not looking for work Secondary school NaN NaN NaN NaN 1 to 2 years NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
19097 Canada No Employed full-time Bachelor's degree A business discipline A few days each month 10 to 19 employees Privately-held limited company, not in startup... 1 to 2 years 1 to 2 years ... Disagree Male Some college/university study, no bachelor's d... White or of European descent Somewhat agree Agree Disagree Agree NaN NaN
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
4 Switzerland No Employed full-time Master's degree Computer science or software engineering Never 10 to 19 employees Privately-held limited company, not in startup... 20 or more years 10 to 11 years ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
3 United States No Employed full-time Doctoral degree A non-computer-focused engineering discipline Less than half the time, but at least one day ... 10,000 or more employees Non-profit/non-governmental organization or pr... 14 to 15 years 9 to 10 years ... Disagree Male A doctoral degree White or of European descent Agree Agree Somewhat agree Strongly agree NaN NaN
2 United Kingdom No Employed full-time Bachelor's degree Computer science or software engineering Less than half the time, but at least one day ... 10,000 or more employees Publicly-traded corporation 20 or more years 20 or more years ... Disagree Male A professional degree White or of European descent Somewhat agree Agree Disagree Agree 113750.0 NaN
1 United Kingdom Yes, full-time Employed part-time Some college/university study without earning ... Computer science or software engineering More than half, but not all, the time 20 to 99 employees Privately-held limited company, not in startup... 9 to 10 years NaN ... Strongly disagree Male A master's degree White or of European descent Somewhat agree Somewhat agree Disagree Strongly agree NaN 37500.0
0 United States No Not employed, and not looking for work Secondary school NaN NaN NaN NaN 2 to 3 years NaN ... Strongly disagree Male High school White or of European descent Strongly disagree Strongly agree Disagree Strongly agree NaN NaN

19102 rows × 151 columns