admin 管理员组

文章数量: 1184232

文章目录

  • 导入数据、查看数据
    • 查看前十条
    • 查看后十条
    • 显示85列显示85行
  • DataFrame
    • 字典转化为DataFrame
    • Dataframe的访问
  • 设置索引、使用索引
    • 设置索引
    • 获取变量的含义
    • 按照索引排序
  • 筛选
    • 与或非
    • 例子
  • 更改数据
    • 更新列名
    • 更新数据
    • apply
    • applymap
    • map
    • replace
  • 添加/删除行和列
    • 合并列
    • 删除列
    • 拆分列
    • 添加数据
    • 合并Dataframe
    • 删除行
  • 数据排序
    • sort_values()
    • 按照索引排序
    • 查看某列前10大

数据集链接:https://survey.stackoverflow.co/

导入数据、查看数据

import pandas as pd
df = pd.read_csv('data/survey_results_public.csv')

查看前十条

df.head(10)
RespondentMainBranchHobbyistOpenSourcerOpenSourceEmploymentCountryStudentEdLevelUndergradMajorEduOtherOrgSizeDevTypeYearsCodeAge1stCodeYearsCodeProCareerSatJobSatMgrIdiotMgrMoneyMgrWantJobSeekLastHireDateLastIntFizzBuzzJobFactorsResumeUpdateCurrencySymbolCurrencyDescCompTotalCompFreqConvertedCompWorkWeekHrsWorkPlanWorkChallengeWorkRemoteWorkLocImpSynCodeRevCodeRevHrsUnitTestsPurchaseHowPurchaseWhatLanguageWorkedWithLanguageDesireNextYearDatabaseWorkedWithDatabaseDesireNextYearPlatformWorkedWithPlatformDesireNextYearWebFrameWorkedWithWebFrameDesireNextYearMiscTechWorkedWithMiscTechDesireNextYearDevEnvironOpSysContainersBlockchainOrgBlockchainIsBetterLifeITpersonOffOnSocialMediaExtraversionScreenNameSOVisit1stSOVisitFreqSOVisitToSOFindAnswerSOTimeSavedSOHowMuchTimeSOAccountSOPartFreqSOJobsEntTeamsSOCommWelcomeChangeSONewContentAgeGenderTransSexualityEthnicityDependentsSurveyLengthSurveyEase
01I am a student who is learning to codeYesNeverThe quality of OSS and closed source software ...Not employed, and not looking for workUnited KingdomNoPrimary/elementary schoolNaNTaught yourself a new language, framework, or ...NaNNaN410NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNHTML/CSS;Java;JavaScript;PythonC;C++;C#;Go;HTML/CSS;Java;JavaScript;Python;SQLSQLiteMySQLMacOS;WindowsAndroid;Arduino;WindowsDjango;FlaskFlask;jQueryNode.jsNode.jsIntelliJ;Notepad++;PyCharmWindowsI do not use containersNaNNaNYesFortunately, someone else has that titleYesTwitterOnlineUsername2017A few times per month or weeklyFind answers to specific questions;Learn how t...3-5 times per weekStack Overflow was much faster31-60 minutesNoNaNNo, I didn't know that Stack Overflow had a jo...No, and I don't know what those areNeutralJust as welcome now as I felt last yearTech articles written by other developers;Indu...14.0ManNoStraight / HeterosexualNaNNoAppropriate in lengthNeither easy nor difficult
12I am a student who is learning to codeNoLess than once per yearThe quality of OSS and closed source software ...Not employed, but looking for workBosnia and HerzegovinaYes, full-timeSecondary school (e.g. American high school, G...NaNTaken an online course in programming or softw...NaNDeveloper, desktop or enterprise applications;...NaN17NaNNaNNaNNaNNaNNaNI am actively looking for a jobI've never had a jobNaNNaNFinancial performance or funding status of the...Something else changed (education, award, medi...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNC++;HTML/CSS;PythonC++;HTML/CSS;JavaScript;SQLNaNMySQLWindowsWindowsDjangoDjangoNaNNaNAtom;PyCharmWindowsI do not use containersNaNUseful across many domains and could change ma...YesYesYesInstagramOnlineUsername2017Daily or almost dailyFind answers to specific questions;Learn how t...3-5 times per weekStack Overflow was much faster11-30 minutesYesA few times per month or weeklyNo, I knew that Stack Overflow had a job board...No, and I don't know what those areYes, somewhatJust as welcome now as I felt last yearTech articles written by other developers;Indu...19.0ManNoStraight / HeterosexualNaNNoAppropriate in lengthNeither easy nor difficult
23I am not primarily a developer, but I write co...YesNeverThe quality of OSS and closed source software ...Employed full-timeThailandNoBachelor’s degree (BA, BS, B.Eng., etc.)Web development or web designTaught yourself a new language, framework, or ...100 to 499 employeesDesigner;Developer, back-end;Developer, front-...3221Slightly satisfiedSlightly satisfiedNot at all confidentNot sureNot sureI’m not actively looking, but I am open to new...1-2 years agoInterview with people in peer rolesNoLanguages, frameworks, and other technologies ...I was preparing for a job searchTHBThai baht23000.0Monthly8820.040.0There's no schedule or spec; I work on what se...Distracting work environment;Inadequate access...Less than once per month / NeverHomeAverageNoNaNNo, but I think we shouldNot sureI have little or no influenceHTML/CSSElixir;HTML/CSSPostgreSQLPostgreSQLNaNNaNNaNOther(s):NaNNaNVim;Visual Studio CodeLinux-basedI do not use containersNaNNaNYesYesYesRedditIn real life (in person)Username2011A few times per weekFind answers to specific questions;Learn how t...6-10 times per weekThey were about the sameNaNYesLess than once per month or monthlyYesNo, I've heard of them, but I am not part of a...NeutralJust as welcome now as I felt last yearTech meetups or events in your area;Courses on...28.0ManNoStraight / HeterosexualNaNYesAppropriate in lengthNeither easy nor difficult
34I am a developer by professionNoNeverThe quality of OSS and closed source software ...Employed full-timeUnited StatesNoBachelor’s degree (BA, BS, B.Eng., etc.)Computer science, computer engineering, or sof...Taken an online course in programming or softw...100 to 499 employeesDeveloper, full-stack316Less than 1 yearVery satisfiedSlightly satisfiedVery confidentNoNot sureI am not interested in new job opportunitiesLess than a year agoWrite code by hand (e.g., on a whiteboard);Int...NoLanguages, frameworks, and other technologies ...I was preparing for a job searchUSDUnited States dollar61000.0Yearly61000.080.0There's no schedule or spec; I work on what se...NaNLess than once per month / NeverHomeA little below averageNoNaNNo, but I think we shouldDevelopers typically have the most influence o...I have little or no influenceC;C++;C#;Python;SQLC;C#;JavaScript;SQLMySQL;SQLiteMySQL;SQLiteLinux;WindowsLinux;WindowsNaNNaN.NET.NETEclipse;Vim;Visual Studio;Visual Studio CodeWindowsI do not use containersNot at allUseful for decentralized currency (i.e., Bitcoin)YesSIGHYesRedditIn real life (in person)Username2014Daily or almost dailyFind answers to specific questions;Pass the ti...1-2 times per weekStack Overflow was much faster31-60 minutesYesLess than once per month or monthlyYesNo, and I don't know what those areNo, not reallyJust as welcome now as I felt last yearTech articles written by other developers;Indu...22.0ManNoStraight / HeterosexualWhite or of European descentNoAppropriate in lengthEasy
45I am a developer by professionYesOnce a month or more oftenOSS is, on average, of HIGHER quality than pro...Employed full-timeUkraineNoBachelor’s degree (BA, BS, B.Eng., etc.)Computer science, computer engineering, or sof...Taken an online course in programming or softw...10,000 or more employeesAcademic researcher;Developer, desktop or ente...16149Very dissatisfiedSlightly dissatisfiedSomewhat confidentYesNoI am not interested in new job opportunitiesLess than a year agoWrite any code;Write code by hand (e.g., on a ...NoIndustry that I'd be working in;Languages, fra...I was preparing for a job searchUAHUkrainian hryvniaNaNNaNNaN55.0There is a schedule and/or spec (made by me or...Being tasked with non-development work;Inadequ...A few days each monthOfficeA little above averageYes, because I see value in code reviewNaNYes, it's part of our processNot sureI have little or no influenceC++;HTML/CSS;Java;JavaScript;Python;SQL;VBAHTML/CSS;Java;JavaScript;SQL;WebAssemblyCouchbase;MongoDB;MySQL;Oracle;PostgreSQL;SQLiteCouchbase;Firebase;MongoDB;MySQL;Oracle;Postgr...Android;Linux;MacOS;Slack;WindowsAndroid;Docker;Kubernetes;Linux;SlackDjango;Express;Flask;jQuery;React.js;SpringFlask;jQuery;React.js;SpringCordova;Node.jsApache Spark;Hadoop;Node.js;React NativeIntelliJ;Notepad++;VimLinux-basedOutside of work, for personal projectsNot at allNaNYesAlso YesYesFacebookIn real life (in person)UsernameI don't rememberMultiple times per dayFind answers to specific questionsMore than 10 times per weekStack Overflow was much fasterNaNYesA few times per month or weeklyNo, I knew that Stack Overflow had a job board...No, I've heard of them, but I am not part of a...Yes, definitelyJust as welcome now as I felt last yearTech meetups or events in your area;Courses on...30.0ManNoStraight / HeterosexualWhite or of European descent;MultiracialNoAppropriate in lengthEasy
56I am not primarily a developer, but I write co...YesNeverThe quality of OSS and closed source software ...Employed full-timeCanadaNoBachelor’s degree (BA, BS, B.Eng., etc.)Mathematics or statisticsTaken an online course in programming or softw...NaNData or business analyst;Data scientist or mac...13153Very satisfiedSlightly satisfiedVery confidentNoYesI am not interested in new job opportunities1-2 years agoWrite any code;Complete a take-home project;In...NoFinancial performance or funding status of the...I heard about a job opportunity (from a recrui...CADCanadian dollar40000.0Monthly366420.015.0There's no schedule or spec; I work on what se...NaNA few days each monthHomeA little above averageNoNaNYes, it's not part of our process but the deve...Not sureI have little or no influenceJava;R;SQLPython;Scala;SQLMongoDB;PostgreSQLPostgreSQLAndroid;Google Cloud Platform;Linux;WindowsAndroid;Google Cloud Platform;Linux;WindowsNaNNaNHadoopHadoop;Pandas;TensorFlow;Unity 3DAndroid Studio;Eclipse;PyCharm;RStudio;Visual ...WindowsI do not use containersNot at allNaNNoYesNoYouTubeIn real life (in person)Login2011A few times per month or weeklyFind answers to specific questionsLess than once per weekStack Overflow was slightly faster60+ minutesYesI have never participated in Q&A on Stack Over...No, I knew that Stack Overflow had a job board...No, and I don't know what those areNo, not reallyJust as welcome now as I felt last yearTech articles written by other developers;Indu...28.0ManNoStraight / HeterosexualEast AsianNoToo longNeither easy nor difficult
67I am a developer by professionNoNeverThe quality of OSS and closed source software ...Independent contractor, freelancer, or self-em...UkraineNoBachelor’s degree (BA, BS, B.Eng., etc.)Another engineering discipline (ex. civil, ele...Taught yourself a new language, framework, or ...Just me - I am a freelancer, sole proprietor, ...Designer;Developer, front-end6174Slightly satisfiedNeither satisfied nor dissatisfiedNaNNaNNaNI’m not actively looking, but I am open to new...NA - I am an independent contractor or self em...Write any codeNoRemote work options;Opportunities for professi...NaNUSDUnited States dollarNaNNaNNaN32.0There is a schedule and/or spec (made by me or...Being tasked with non-development work;Distrac...All or almost all the time (I'm full-time remote)Other place, such as a coworking space or cafeAverageYes, because I see value in code review6.0NaNNaNNaNHTML/CSS;JavaScriptHTML/CSS;JavaScriptNaNNaNMacOS;WindowsMacOS;WindowsReact.jsReact.jsNaNNaNPHPStormWindowsI do not use containersNaNUseful for decentralized currency (i.e., Bitcoin)NoYesNoYouTubeNaNNaN2014Daily or almost dailyFind answers to specific questions3-5 times per weekNaNNaNYesLess than once per month or monthlyYesNo, and I don't know what those areNeutralA lot more welcome now than last yearNaN42.0ManNoStraight / HeterosexualWhite or of European descentYesAppropriate in lengthNeither easy nor difficult
78I code primarily as a hobbyYesLess than once per yearOSS is, on average, of HIGHER quality than pro...Not employed, but looking for workIndiaNaNBachelor’s degree (BA, BS, B.Eng., etc.)Computer science, computer engineering, or sof...Taught yourself a new language, framework, or ...NaNDeveloper, back-end;Engineer, site reliability816NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNBash/Shell/PowerShell;C;C++;HTML/CSS;Java;Java...Bash/Shell/PowerShell;C;C++;Elixir;Erlang;Go;P...Cassandra;Elasticsearch;MongoDB;MySQL;Oracle;R...Cassandra;DynamoDB;Elasticsearch;Firebase;Mong...AWS;Docker;Heroku;Linux;MacOS;SlackAndroid;Arduino;AWS;Docker;Google Cloud Platfo...Express;Flask;React.js;SpringDjango;Express;Flask;React.js;Vue.jsHadoop;Node.js;PandasAnsible;Apache Spark;Chef;Hadoop;Node.js;Panda...Atom;IntelliJ;IPython / Jupyter;PyCharm;Visual...Linux-basedDevelopment;Testing;Production;Outside of work...NaNUseful across many domains and could change ma...YesSIGHYesYouTubeIn real life (in person)Handle2012A few times per weekFind answers to specific questions;Learn how t...Less than once per weekStack Overflow was slightly faster11-30 minutesYesLess than once per month or monthlyYesNo, and I don't know what those areYes, definitelyA lot more welcome now than last yearTech articles written by other developers;Indu...24.0ManNoStraight / HeterosexualNaNNaNAppropriate in lengthNeither easy nor difficult
89I am a developer by professionYesOnce a month or more oftenThe quality of OSS and closed source software ...Employed full-timeNew ZealandNoSome college/university study without earning ...Computer science, computer engineering, or sof...Taken an online course in programming or softw...10 to 19 employeesDatabase administrator;Developer, back-end;Dev...12114Slightly satisfiedSlightly satisfiedSomewhat confidentNoNot sureI’m not actively looking, but I am open to new...Less than a year agoWrite any code;Interview with people in peer r...YesFinancial performance or funding status of the...I was preparing for a job searchNZDNew Zealand dollar138000.0Yearly95179.032.0There is a schedule and/or spec (made by me or...Being tasked with non-development work;Inadequ...Less than once per month / NeverOfficeA little above averageYes, because I see value in code review12.0Yes, it's not part of our process but the deve...Not sureI have some influenceBash/Shell/PowerShell;C#;HTML/CSS;JavaScript;P...Bash/Shell/PowerShell;C;HTML/CSS;JavaScript;Ru...DynamoDB;PostgreSQL;SQLitePostgreSQL;Redis;SQLiteAWS;Docker;Heroku;Linux;MacOS;SlackAWS;Docker;Heroku;Linux;MacOS;Slack;Other(s):Express;Ruby on Rails;Other(s):Express;Ruby on Rails;Other(s):Node.js;Unity 3DNode.jsVimMacOSDevelopment;Testing;ProductionNot at allAn irresponsible use of resourcesNoSIGHYesTwitterIn real life (in person)Username2013Daily or almost dailyFind answers to specific questions;Contribute ...3-5 times per weekThey were about the sameNaNYesLess than once per month or monthlyNo, I knew that Stack Overflow had a job board...No, and I don't know what those areYes, somewhatJust as welcome now as I felt last yearNaN23.0ManNoBisexualWhite or of European descentNoAppropriate in lengthNeither easy nor difficult
910I am a developer by professionYesOnce a month or more oftenOSS is, on average, of HIGHER quality than pro...Employed full-timeIndiaNoMaster’s degree (MA, MS, M.Eng., MBA, etc.)NaNNaN10,000 or more employeesData or business analyst;Data scientist or mac...122010Slightly dissatisfiedSlightly dissatisfiedSomewhat confidentYesYesI’m not actively looking, but I am open to new...3-4 years agoNaNNoLanguages, frameworks, and other technologies ...NaNINRIndian rupee950000.0Yearly13293.070.0There's no schedule or spec; I work on what se...NaNA few days each monthHomeFar above averageYes, because I see value in code review4.0Yes, it's part of our processNaNNaNC#;Go;JavaScript;Python;R;SQLC#;Go;JavaScript;Kotlin;Python;R;SQLElasticsearch;MongoDB;Microsoft SQL Server;MyS...Elasticsearch;MongoDB;Microsoft SQL ServerLinux;WindowsAndroid;Linux;Raspberry Pi;WindowsAngular/Angular.js;ASP.NET;Django;Express;Flas...Angular/Angular.js;ASP.NET;Django;Express;Flas....NET;Node.js;Pandas;Torch/PyTorch.NET;Node.js;TensorFlow;Torch/PyTorchAndroid Studio;Eclipse;IPython / Jupyter;Notep...WindowsNaNNot at allUseful for immutable record keeping outside of...NoYesYesYouTubeNeitherScreen NameNaNMultiple times per dayFind answers to specific questions;Get a sense...3-5 times per weekThey were about the sameNaNYesA few times per month or weeklyYesNo, and I don't know what those areYes, somewhatSomewhat less welcome now than last yearTech articles written by other developers;Tech...NaNNaNNaNNaNNaNYesToo longDifficult

查看后十条

df.tail(10)
RespondentMainBranchHobbyistOpenSourcerOpenSourceEmploymentCountryStudentEdLevelUndergradMajorEduOtherOrgSizeDevTypeYearsCodeAge1stCodeYearsCodeProCareerSatJobSatMgrIdiotMgrMoneyMgrWantJobSeekLastHireDateLastIntFizzBuzzJobFactorsResumeUpdateCurrencySymbolCurrencyDescCompTotalCompFreqConvertedCompWorkWeekHrsWorkPlanWorkChallengeWorkRemoteWorkLocImpSynCodeRevCodeRevHrsUnitTestsPurchaseHowPurchaseWhatLanguageWorkedWithLanguageDesireNextYearDatabaseWorkedWithDatabaseDesireNextYearPlatformWorkedWithPlatformDesireNextYearWebFrameWorkedWithWebFrameDesireNextYearMiscTechWorkedWithMiscTechDesireNextYearDevEnvironOpSysContainersBlockchainOrgBlockchainIsBetterLifeITpersonOffOnSocialMediaExtraversionScreenNameSOVisit1stSOVisitFreqSOVisitToSOFindAnswerSOTimeSavedSOHowMuchTimeSOAccountSOPartFreqSOJobsEntTeamsSOCommWelcomeChangeSONewContentAgeGenderTransSexualityEthnicityDependentsSurveyLengthSurveyEase
8887388062NaNNoNeverOSS is, on average, of LOWER quality than prop...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
8887488076NaNNoNeverOSS is, on average, of HIGHER quality than pro...Employed full-timeNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
8887588182NaNYesOnce a month or more oftenOSS is, on average, of HIGHER quality than pro...Employed part-timePakistanNaNSecondary school (e.g. American high school, G...NaNTaken an online course in programming or softw...10 to 19 employeesAcademic researcher1Younger than 5 yearsLess than 1 yearNaNNaNVery confidentNot sureYesNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNHTML/CSS;Java;JavaScriptNaNNaNNaNGoogle Cloud PlatformNaNOther(s):NaNOther(s):NaNAndroid StudioWindowsDevelopmentNaNUseful across many domains and could change ma...YesAlso YesWhat?TwitterNeitherUsernameNaNI have never visited Stack Overflow (before to...Get a sense of belonging to the developer comm...Less than once per weekThe other resource was slightly faster60+ minutesNaNNaNNo, I didn't know that Stack Overflow had a jo...No, and I don't know what those areNeutralNot applicable - I did not use Stack Overflow ...Courses on technologies you're interested inNaNManNoStraight / HeterosexualNaNYesToo shortNeither easy nor difficult
8887688212NaNNoLess than once per yearOSS is, on average, of HIGHER quality than pro...Employed full-timeSpainNoSecondary school (e.g. American high school, G...NaNTaught yourself a new language, framework, or ...10 to 19 employeesDesigner;Developer, front-end;Developer, full-...18715NaNNaNSomewhat confidentYesI am already a managerNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNHTML/CSS;JavaScript;PythonJavaScriptMySQL;PostgreSQLPostgreSQLNaNArduinoDjango;React.jsDjango;React.jsNaNNaNAtom;Visual Studio CodeMacOSI do not use containersNon-currency applications of blockchainUseful for immutable record keeping outside of...NoSIGHNoWhatsAppIn real life (in person)Username2008A few times per weekFind answers to specific questions6-10 times per weekStack Overflow was slightly faster0-10 minutesYesI have never participated in Q&A on Stack Over...No, I didn't know that Stack Overflow had a jo...No, and I don't know what those areNo, not at allNaNTech articles written by other developers;Indu...40.0ManNoStraight / HeterosexualWhite or of European descentNoAppropriate in lengthEasy
8887788282NaNYesOnce a month or more oftenThe quality of OSS and closed source software ...Not employed, but looking for workUnited StatesNoSome college/university study without earning ...Computer science, computer engineering, or sof...Taught yourself a new language, framework, or ...NaNDeveloper, back-end;Developer, desktop or ente...381038NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNBash/Shell/PowerShell;Go;HTML/CSS;JavaScript;W...Bash/Shell/PowerShell;C;Go;HTML/CSS;JavaScript...NaNNaNLinuxLinux;Raspberry PiReact.jsVue.jsNode.jsAnsibleVimLinux-basedI do not use containersNaNAn irresponsible use of resourcesNoNaNYesI don't use social mediaIn real life (in person)UsernameI don't rememberA few times per month or weeklyFind answers to specific questions1-2 times per weekThey were about the sameNaNYesI have never participated in Q&A on Stack Over...YesNo, and I don't know what those areNo, not reallyJust as welcome now as I felt last yearNaNNaNManNoStraight / HeterosexualNaNNoToo shortNeither easy nor difficult
8887888377NaNYesLess than once a month but more than once per ...The quality of OSS and closed source software ...Not employed, and not looking for workCanadaNoPrimary/elementary schoolNaNTaught yourself a new language, framework, or ...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNHTML/CSS;JavaScript;Other(s):C++;HTML/CSS;JavaScript;SQL;WebAssembly;Other(s):Firebase;SQLiteFirebase;MySQL;SQLiteLinuxGoogle Cloud Platform;LinuxjQueryjQuery;Vue.jsNode.jsReact Native;Unity 3D;Unreal EngineAtom;Visual Studio;Visual Studio CodeWindowsI do not use containersNaNUseful across many domains and could change ma...YesYesWhat?YouTubeNaNUsernameI don't rememberA few times per weekFind answers to specific questions;Learn how t...3-5 times per weekStack Overflow was slightly faster11-30 minutesYesI have never participated in Q&A on Stack Over...No, I knew that Stack Overflow had a job board...No, I've heard of them, but I am not part of a...No, not at allNaNTech articles written by other developers;Tech...NaNManNoNaNNaNNoAppropriate in lengthEasy
8887988601NaNNoNeverThe quality of OSS and closed source software ...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
8888088802NaNNoNeverNaNEmployed full-timeNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
8888188816NaNNoNeverOSS is, on average, of HIGHER quality than pro...Independent contractor, freelancer, or self-em...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
8888288863NaNYesLess than once per yearOSS is, on average, of HIGHER quality than pro...Not employed, and not looking for workSpainYes, full-timeProfessional degree (JD, MD, etc.)Computer science, computer engineering, or sof...Taken an online course in programming or softw...NaNNaN8113NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNBash/Shell/PowerShell;HTML/CSS;Java;JavaScript...C;C++;C#;HTML/CSS;Java;Objective-C;SQL;SwiftDynamoDB;MariaDB;Microsoft SQL Server;MySQLMariaDB;MySQL;Oracle;SQLiteiOS;Linux;MacOS;WordPressAndroid;AWS;Google Cloud Platform;IBM Cloud or...Django;jQuery;React.jsDjangoUnity 3D;Unreal EngineNaNAndroid Studio;Atom;Eclipse;NetBeans;Notepad++...Linux-basedProductionNaNUseful for decentralized currency (i.e., Bitcoin)YesAlso YesYesWhatsAppIn real life (in person)NaN2012Daily or almost dailyFind answers to specific questions;Learn how t...6-10 times per weekStack Overflow was much faster11-30 minutesYesA few times per month or weeklyYesNo, I've heard of them, but I am not part of a...Yes, somewhatSomewhat less welcome now than last yearTech articles written by other developers;Indu...18.0ManNoStraight / HeterosexualHispanic or Latino/Latina;White or of European...NoAppropriate in lengthEasy
df.shape
(88883, 85)
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 88883 entries, 0 to 88882
Data columns (total 85 columns):
 #   Column                  Non-Null Count  Dtype  
---  ------                  --------------  -----  
 0   Respondent              88883 non-null  int64  
 1   MainBranch              88331 non-null  object 
 2   Hobbyist                88883 non-null  object 
 3   OpenSourcer             88883 non-null  object 
 4   OpenSource              86842 non-null  object 
 5   Employment              87181 non-null  object 
 6   Country                 88751 non-null  object 
 7   Student                 87014 non-null  object 
 8   EdLevel                 86390 non-null  object 
 9   UndergradMajor          75614 non-null  object 
 10  EduOther                84260 non-null  object 
 11  OrgSize                 71791 non-null  object 
 12  DevType                 81335 non-null  object 
 13  YearsCode               87938 non-null  object 
 14  Age1stCode              87634 non-null  object 
 15  YearsCodePro            74331 non-null  object 
 16  CareerSat               72847 non-null  object 
 17  JobSat                  70988 non-null  object 
 18  MgrIdiot                61159 non-null  object 
 19  MgrMoney                61157 non-null  object 
 20  MgrWant                 61232 non-null  object 
 21  JobSeek                 80555 non-null  object 
 22  LastHireDate            79854 non-null  object 
 23  LastInt                 67155 non-null  object 
 24  FizzBuzz                71344 non-null  object 
 25  JobFactors              79371 non-null  object 
 26  ResumeUpdate            77877 non-null  object 
 27  CurrencySymbol          71392 non-null  object 
 28  CurrencyDesc            71392 non-null  object 
 29  CompTotal               55945 non-null  float64
 30  CompFreq                63268 non-null  object 
 31  ConvertedComp           55823 non-null  float64
 32  WorkWeekHrs             64503 non-null  float64
 33  WorkPlan                68914 non-null  object 
 34  WorkChallenge           68141 non-null  object 
 35  WorkRemote              70284 non-null  object 
 36  WorkLoc                 70055 non-null  object 
 37  ImpSyn                  71779 non-null  object 
 38  CodeRev                 70390 non-null  object 
 39  CodeRevHrs              49790 non-null  float64
 40  UnitTests               62668 non-null  object 
 41  PurchaseHow             61108 non-null  object 
 42  PurchaseWhat            62029 non-null  object 
 43  LanguageWorkedWith      87569 non-null  object 
 44  LanguageDesireNextYear  84088 non-null  object 
 45  DatabaseWorkedWith      76026 non-null  object 
 46  DatabaseDesireNextYear  69147 non-null  object 
 47  PlatformWorkedWith      80714 non-null  object 
 48  PlatformDesireNextYear  77443 non-null  object 
 49  WebFrameWorkedWith      65022 non-null  object 
 50  WebFrameDesireNextYear  62944 non-null  object 
 51  MiscTechWorkedWith      59586 non-null  object 
 52  MiscTechDesireNextYear  64511 non-null  object 
 53  DevEnviron              87317 non-null  object 
 54  OpSys                   87851 non-null  object 
 55  Containers              85366 non-null  object 
 56  BlockchainOrg           48175 non-null  object 
 57  BlockchainIs            60165 non-null  object 
 58  BetterLife              86269 non-null  object 
 59  ITperson                87141 non-null  object 
 60  OffOn                   86663 non-null  object 
 61  SocialMedia             84437 non-null  object 
 62  Extraversion            87305 non-null  object 
 63  ScreenName              80486 non-null  object 
 64  SOVisit1st              83877 non-null  object 
 65  SOVisitFreq             88263 non-null  object 
 66  SOVisitTo               88086 non-null  object 
 67  SOFindAnswer            87816 non-null  object 
 68  SOTimeSaved             86344 non-null  object 
 69  SOHowMuchTime           68378 non-null  object 
 70  SOAccount               87828 non-null  object 
 71  SOPartFreq              74692 non-null  object 
 72  SOJobs                  88066 non-null  object 
 73  EntTeams                87841 non-null  object 
 74  SOComm                  88131 non-null  object 
 75  WelcomeChange           85855 non-null  object 
 76  SONewContent            69560 non-null  object 
 77  Age                     79210 non-null  float64
 78  Gender                  85406 non-null  object 
 79  Trans                   83607 non-null  object 
 80  Sexuality               76147 non-null  object 
 81  Ethnicity               76668 non-null  object 
 82  Dependents              83059 non-null  object 
 83  SurveyLength            86984 non-null  object 
 84  SurveyEase              87081 non-null  object 
dtypes: float64(5), int64(1), object(79)
memory usage: 57.6+ MB

显示85列显示85行

pd.set_option('display.max_columns',85)
pd.set_option('display.max_rows',85)
schema_df = pd.read_csv('data/survey_results_schema.csv')
schema_df
ColumnQuestionText
0RespondentRandomized respondent ID number (not in order ...
1MainBranchWhich of the following options best describes ...
2HobbyistDo you code as a hobby?
3OpenSourcerHow often do you contribute to open source?
4OpenSourceHow do you feel about the quality of open sour...
5EmploymentWhich of the following best describes your cur...
6CountryIn which country do you currently reside?
7StudentAre you currently enrolled in a formal, degree...
8EdLevelWhich of the following best describes the high...
9UndergradMajorWhat was your main or most important field of ...
10EduOtherWhich of the following types of non-degree edu...
11OrgSizeApproximately how many people are employed by ...
12DevTypeWhich of the following describe you? Please se...
13YearsCodeIncluding any education, how many years have y...
14Age1stCodeAt what age did you write your first line of c...
15YearsCodeProHow many years have you coded professionally (...
16CareerSatOverall, how satisfied are you with your caree...
17JobSatHow satisfied are you with your current job? (...
18MgrIdiotHow confident are you that your manager knows ...
19MgrMoneyDo you believe that you need to be a manager t...
20MgrWantDo you want to become a manager yourself in th...
21JobSeekWhich of the following best describes your cur...
22LastHireDateWhen was the last time that you took a job wit...
23LastIntIn your most recent successful job interview (...
24FizzBuzzHave you ever been asked to solve FizzBuzz in ...
25JobFactorsImagine that you are deciding between two job ...
26ResumeUpdateThink back to the last time you updated your r...
27CurrencySymbolWhich currency do you use day-to-day? If your ...
28CurrencyDescWhich currency do you use day-to-day? If your ...
29CompTotalWhat is your current total compensation (salar...
30CompFreqIs that compensation weekly, monthly, or yearly?
31ConvertedCompSalary converted to annual USD salaries using ...
32WorkWeekHrsOn average, how many hours per week do you work?
33WorkPlanHow structured or planned is your work?
34WorkChallengeOf these options, what are your greatest chall...
35WorkRemoteHow often do you work remotely?
36WorkLocWhere would you prefer to work?
37ImpSynFor the specific work you do, and the years of...
38CodeRevDo you review code as part of your work?
39CodeRevHrsOn average, how many hours per week do you spe...
40UnitTestsDoes your company regularly employ unit tests ...
41PurchaseHowHow does your company make decisions about pur...
42PurchaseWhatWhat level of influence do you, personally, ha...
43LanguageWorkedWithWhich of the following programming, scripting,...
44LanguageDesireNextYearWhich of the following programming, scripting,...
45DatabaseWorkedWithWhich of the following database environments h...
46DatabaseDesireNextYearWhich of the following database environments h...
47PlatformWorkedWithWhich of the following platforms have you done...
48PlatformDesireNextYearWhich of the following platforms have you done...
49WebFrameWorkedWithWhich of the following web frameworks have you...
50WebFrameDesireNextYearWhich of the following web frameworks have you...
51MiscTechWorkedWithWhich of the following other frameworks, libra...
52MiscTechDesireNextYearWhich of the following other frameworks, libra...
53DevEnvironWhich development environment(s) do you use re...
54OpSysWhat is the primary operating system in which ...
55ContainersHow do you use containers (Docker, Open Contai...
56BlockchainOrgHow is your organization thinking about or imp...
57BlockchainIsBlockchain / cryptocurrency technology is prim...
58BetterLifeDo you think people born today will have a bet...
59ITpersonAre you the "IT support person" for your family?
60OffOnHave you tried turning it off and on again?
61SocialMediaWhat social media site do you use the most?
62ExtraversionDo you prefer online chat or IRL conversations?
63ScreenNameWhat do you call it?
64SOVisit1stTo the best of your memory, when did you first...
65SOVisitFreqHow frequently would you say you visit Stack O...
66SOVisitToI visit Stack Overflow to... (check all that a...
67SOFindAnswerOn average, how many times a week do you find ...
68SOTimeSavedThink back to the last time you solved a codin...
69SOHowMuchTimeAbout how much time did you save? If you're no...
70SOAccountDo you have a Stack Overflow account?
71SOPartFreqHow frequently would you say you participate i...
72SOJobsHave you ever used or visited Stack Overflow J...
73EntTeamsHave you ever used Stack Overflow for Enterpri...
74SOCommDo you consider yourself a member of the Stack...
75WelcomeChangeCompared to last year, how welcome do you feel...
76SONewContentWould you like to see any of the following on ...
77AgeWhat is your age (in years)? If you prefer not...
78GenderWhich of the following do you currently identi...
79TransDo you identify as transgender?
80SexualityWhich of the following do you currently identi...
81EthnicityWhich of the following do you identify as? Ple...
82DependentsDo you have any dependents (e.g., children, el...
83SurveyLengthHow do you feel about the length of the survey...
84SurveyEaseHow easy or difficult was this survey to compl...

DataFrame

字典转化为DataFrame

people = {
    "first": ["Corey", 'Jane', 'John'], 
    "last": ["Schafer", 'Doe', 'Doe'], 
    "email": ["CoreyMSchafer@gmail", 'JaneDoe@email', 'JohnDoe@email']
}
people['email']
['CoreyMSchafer@gmail', 'JaneDoe@email', 'JohnDoe@email']
import pandas as pd
df = pd.DataFrame(people)

Dataframe的访问

df
firstlastemail
0CoreySchaferCoreyMSchafer@gmail
1JaneDoeJaneDoe@email
2JohnDoeJohnDoe@email
df['email']
0    CoreyMSchafer@gmail
1          JaneDoe@email
2          JohnDoe@email
Name: email, dtype: object
type(df['email'])
pandas.core.series.Series
df.email
0    CoreyMSchafer@gmail
1          JaneDoe@email
2          JohnDoe@email
Name: email, dtype: object
  • Dataframe访问多列
df[['last','email']]
lastemail
0SchaferCoreyMSchafer@gmail
1DoeJaneDoe@email
2DoeJohnDoe@email

单列返回的是series多列返回的是dataframe

df.columns
Index(['first', 'last', 'email'], dtype='object')
df.iloc[0]
first                      Corey
last                     Schafer
email    CoreyMSchafer@gmail
Name: 0, dtype: object
  • 访问1,2行的email列
df
firstlastemail
0CoreySchaferCoreyMSchafer@gmail
1JaneDoeJaneDoe@email
2JohnDoeJohnDoe@email
df.iloc[[0,1],2]
0    CoreyMSchafer@gmail
1          JaneDoe@email
Name: email, dtype: object
df.loc[[0,1],['email','last']]
emaillast
0CoreyMSchafer@gmailSchafer
1JaneDoe@emailDoe
df = pd.read_csv('data/survey_results_public.csv')
schema_df = pd.read_csv('data/survey_results_schema.csv')
pd.set_option('display.max_columns', 85)
pd.set_option('display.max_rows', 85)
df.columns
Index(['Respondent', 'MainBranch', 'Hobbyist', 'OpenSourcer', 'OpenSource',
       'Employment', 'Country', 'Student', 'EdLevel', 'UndergradMajor',
       'EduOther', 'OrgSize', 'DevType', 'YearsCode', 'Age1stCode',
       'YearsCodePro', 'CareerSat', 'JobSat', 'MgrIdiot', 'MgrMoney',
       'MgrWant', 'JobSeek', 'LastHireDate', 'LastInt', 'FizzBuzz',
       'JobFactors', 'ResumeUpdate', 'CurrencySymbol', 'CurrencyDesc',
       'CompTotal', 'CompFreq', 'ConvertedComp', 'WorkWeekHrs', 'WorkPlan',
       'WorkChallenge', 'WorkRemote', 'WorkLoc', 'ImpSyn', 'CodeRev',
       'CodeRevHrs', 'UnitTests', 'PurchaseHow', 'PurchaseWhat',
       'LanguageWorkedWith', 'LanguageDesireNextYear', 'DatabaseWorkedWith',
       'DatabaseDesireNextYear', 'PlatformWorkedWith',
       'PlatformDesireNextYear', 'WebFrameWorkedWith',
       'WebFrameDesireNextYear', 'MiscTechWorkedWith',
       'MiscTechDesireNextYear', 'DevEnviron', 'OpSys', 'Containers',
       'BlockchainOrg', 'BlockchainIs', 'BetterLife', 'ITperson', 'OffOn',
       'SocialMedia', 'Extraversion', 'ScreenName', 'SOVisit1st',
       'SOVisitFreq', 'SOVisitTo', 'SOFindAnswer', 'SOTimeSaved',
       'SOHowMuchTime', 'SOAccount', 'SOPartFreq', 'SOJobs', 'EntTeams',
       'SOComm', 'WelcomeChange', 'SONewContent', 'Age', 'Gender', 'Trans',
       'Sexuality', 'Ethnicity', 'Dependents', 'SurveyLength', 'SurveyEase'],
      dtype='object')
df['Hobbyist']
0        Yes
1         No
2        Yes
3         No
4        Yes
        ... 
88878    Yes
88879     No
88880     No
88881     No
88882    Yes
Name: Hobbyist, Length: 88883, dtype: object
  • 查看多少Yes多少No
df['Hobbyist'].value_counts()
Yes    71257
No     17626
Name: Hobbyist, dtype: int64
df.loc[0]
Respondent                                                                1
MainBranch                           I am a student who is learning to code
Hobbyist                                                                Yes
OpenSourcer                                                           Never
OpenSource                The quality of OSS and closed source software ...
Employment                           Not employed, and not looking for work
Country                                                      United Kingdom
Student                                                                  No
EdLevel                                           Primary/elementary school
UndergradMajor                                                          NaN
EduOther                  Taught yourself a new language, framework, or ...
OrgSize                                                                 NaN
DevType                                                                 NaN
YearsCode                                                                 4
Age1stCode                                                               10
YearsCodePro                                                            NaN
CareerSat                                                               NaN
JobSat                                                                  NaN
MgrIdiot                                                                NaN
MgrMoney                                                                NaN
MgrWant                                                                 NaN
JobSeek                                                                 NaN
LastHireDate                                                            NaN
LastInt                                                                 NaN
FizzBuzz                                                                NaN
JobFactors                                                              NaN
ResumeUpdate                                                            NaN
CurrencySymbol                                                          NaN
CurrencyDesc                                                            NaN
CompTotal                                                               NaN
CompFreq                                                                NaN
ConvertedComp                                                           NaN
WorkWeekHrs                                                             NaN
WorkPlan                                                                NaN
WorkChallenge                                                           NaN
WorkRemote                                                              NaN
WorkLoc                                                                 NaN
ImpSyn                                                                  NaN
CodeRev                                                                 NaN
CodeRevHrs                                                              NaN
UnitTests                                                               NaN
PurchaseHow                                                             NaN
PurchaseWhat                                                            NaN
LanguageWorkedWith                          HTML/CSS;Java;JavaScript;Python
LanguageDesireNextYear      C;C++;C#;Go;HTML/CSS;Java;JavaScript;Python;SQL
DatabaseWorkedWith                                                   SQLite
DatabaseDesireNextYear                                                MySQL
PlatformWorkedWith                                            MacOS;Windows
PlatformDesireNextYear                              Android;Arduino;Windows
WebFrameWorkedWith                                             Django;Flask
WebFrameDesireNextYear                                         Flask;jQuery
MiscTechWorkedWith                                                  Node.js
MiscTechDesireNextYear                                              Node.js
DevEnviron                                       IntelliJ;Notepad++;PyCharm
OpSys                                                               Windows
Containers                                          I do not use containers
BlockchainOrg                                                           NaN
BlockchainIs                                                            NaN
BetterLife                                                              Yes
ITperson                           Fortunately, someone else has that title
OffOn                                                                   Yes
SocialMedia                                                         Twitter
Extraversion                                                         Online
ScreenName                                                         Username
SOVisit1st                                                             2017
SOVisitFreq                                 A few times per month or weekly
SOVisitTo                 Find answers to specific questions;Learn how t...
SOFindAnswer                                             3-5 times per week
SOTimeSaved                                  Stack Overflow was much faster
SOHowMuchTime                                                 31-60 minutes
SOAccount                                                                No
SOPartFreq                                                              NaN
SOJobs                    No, I didn't know that Stack Overflow had a jo...
EntTeams                                No, and I don't know what those are
SOComm                                                              Neutral
WelcomeChange                       Just as welcome now as I felt last year
SONewContent              Tech articles written by other developers;Indu...
Age                                                                    14.0
Gender                                                                  Man
Trans                                                                    No
Sexuality                                           Straight / Heterosexual
Ethnicity                                                               NaN
Dependents                                                               No
SurveyLength                                          Appropriate in length
SurveyEase                                       Neither easy nor difficult
Name: 0, dtype: object
df.loc[0:2,'Hobbyist': 'Employment']
HobbyistOpenSourcerOpenSourceEmployment
0YesNeverThe quality of OSS and closed source software ...Not employed, and not looking for work
1NoLess than once per yearThe quality of OSS and closed source software ...Not employed, but looking for work
2YesNeverThe quality of OSS and closed source software ...Employed full-time

设置索引、使用索引

设置索引

people = {
    "first": ["Corey", 'Jane', 'John'], 
    "last": ["Schafer", 'Doe', 'Doe'], 
    "email": ["CoreyMSchafer@gmail", 'JaneDoe@email', 'JohnDoe@email']
}
import pandas as pd
df = pd.DataFrame(people)
df
firstlastemail
0CoreySchaferCoreyMSchafer@gmail
1JaneDoeJaneDoe@email
2JohnDoeJohnDoe@email
  • 将email列设置为索引
df.set_index('email')
firstlast
email
CoreyMSchafer@gmailCoreySchafer
JaneDoe@emailJaneDoe
JohnDoe@emailJohnDoe
df
firstlastemail
0CoreySchaferCoreyMSchafer@gmail
1JaneDoeJaneDoe@email
2JohnDoeJohnDoe@email

设置索引并没有对在df基础上设置,df仍然没变,仍使用默认索引值,所以需要添加inplace=True

df.set_index('email',inplace=True)
df
firstlast
email
CoreyMSchafer@gmailCoreySchafer
JaneDoe@emailJaneDoe
JohnDoe@emailJohnDoe
df.index
Index(['CoreyMSchafer@gmail', 'JaneDoe@email', 'JohnDoe@email'], dtype='object', name='email')
df.loc['CoreyMSchafer@gmail','last']
'Schafer'
  • 重置索引
df.reset_index(inplace=True)
df
indexemailfirstlast
00CoreyMSchafer@gmailCoreySchafer
11JaneDoe@emailJaneDoe
22JohnDoe@emailJohnDoe
  • 读入csv时,设置索引列
df = pd.read_csv('data/survey_results_public.csv',index_col='Respondent')
pd.set_option('display.max_columns', 85)
pd.set_option('display.max_rows', 85)
df.head()
MainBranchHobbyistOpenSourcerOpenSourceEmploymentCountryStudentEdLevelUndergradMajorEduOtherOrgSizeDevTypeYearsCodeAge1stCodeYearsCodeProCareerSatJobSatMgrIdiotMgrMoneyMgrWantJobSeekLastHireDateLastIntFizzBuzzJobFactorsResumeUpdateCurrencySymbolCurrencyDescCompTotalCompFreqConvertedCompWorkWeekHrsWorkPlanWorkChallengeWorkRemoteWorkLocImpSynCodeRevCodeRevHrsUnitTestsPurchaseHowPurchaseWhatLanguageWorkedWithLanguageDesireNextYearDatabaseWorkedWithDatabaseDesireNextYearPlatformWorkedWithPlatformDesireNextYearWebFrameWorkedWithWebFrameDesireNextYearMiscTechWorkedWithMiscTechDesireNextYearDevEnvironOpSysContainersBlockchainOrgBlockchainIsBetterLifeITpersonOffOnSocialMediaExtraversionScreenNameSOVisit1stSOVisitFreqSOVisitToSOFindAnswerSOTimeSavedSOHowMuchTimeSOAccountSOPartFreqSOJobsEntTeamsSOCommWelcomeChangeSONewContentAgeGenderTransSexualityEthnicityDependentsSurveyLengthSurveyEase
Respondent
1I am a student who is learning to codeYesNeverThe quality of OSS and closed source software ...Not employed, and not looking for workUnited KingdomNoPrimary/elementary schoolNaNTaught yourself a new language, framework, or ...NaNNaN410NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNHTML/CSS;Java;JavaScript;PythonC;C++;C#;Go;HTML/CSS;Java;JavaScript;Python;SQLSQLiteMySQLMacOS;WindowsAndroid;Arduino;WindowsDjango;FlaskFlask;jQueryNode.jsNode.jsIntelliJ;Notepad++;PyCharmWindowsI do not use containersNaNNaNYesFortunately, someone else has that titleYesTwitterOnlineUsername2017A few times per month or weeklyFind answers to specific questions;Learn how t...3-5 times per weekStack Overflow was much faster31-60 minutesNoNaNNo, I didn't know that Stack Overflow had a jo...No, and I don't know what those areNeutralJust as welcome now as I felt last yearTech articles written by other developers;Indu...14.0ManNoStraight / HeterosexualNaNNoAppropriate in lengthNeither easy nor difficult
2I am a student who is learning to codeNoLess than once per yearThe quality of OSS and closed source software ...Not employed, but looking for workBosnia and HerzegovinaYes, full-timeSecondary school (e.g. American high school, G...NaNTaken an online course in programming or softw...NaNDeveloper, desktop or enterprise applications;...NaN17NaNNaNNaNNaNNaNNaNI am actively looking for a jobI've never had a jobNaNNaNFinancial performance or funding status of the...Something else changed (education, award, medi...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNC++;HTML/CSS;PythonC++;HTML/CSS;JavaScript;SQLNaNMySQLWindowsWindowsDjangoDjangoNaNNaNAtom;PyCharmWindowsI do not use containersNaNUseful across many domains and could change ma...YesYesYesInstagramOnlineUsername2017Daily or almost dailyFind answers to specific questions;Learn how t...3-5 times per weekStack Overflow was much faster11-30 minutesYesA few times per month or weeklyNo, I knew that Stack Overflow had a job board...No, and I don't know what those areYes, somewhatJust as welcome now as I felt last yearTech articles written by other developers;Indu...19.0ManNoStraight / HeterosexualNaNNoAppropriate in lengthNeither easy nor difficult
3I am not primarily a developer, but I write co...YesNeverThe quality of OSS and closed source software ...Employed full-timeThailandNoBachelor’s degree (BA, BS, B.Eng., etc.)Web development or web designTaught yourself a new language, framework, or ...100 to 499 employeesDesigner;Developer, back-end;Developer, front-...3221Slightly satisfiedSlightly satisfiedNot at all confidentNot sureNot sureI’m not actively looking, but I am open to new...1-2 years agoInterview with people in peer rolesNoLanguages, frameworks, and other technologies ...I was preparing for a job searchTHBThai baht23000.0Monthly8820.040.0There's no schedule or spec; I work on what se...Distracting work environment;Inadequate access...Less than once per month / NeverHomeAverageNoNaNNo, but I think we shouldNot sureI have little or no influenceHTML/CSSElixir;HTML/CSSPostgreSQLPostgreSQLNaNNaNNaNOther(s):NaNNaNVim;Visual Studio CodeLinux-basedI do not use containersNaNNaNYesYesYesRedditIn real life (in person)Username2011A few times per weekFind answers to specific questions;Learn how t...6-10 times per weekThey were about the sameNaNYesLess than once per month or monthlyYesNo, I've heard of them, but I am not part of a...NeutralJust as welcome now as I felt last yearTech meetups or events in your area;Courses on...28.0ManNoStraight / HeterosexualNaNYesAppropriate in lengthNeither easy nor difficult
4I am a developer by professionNoNeverThe quality of OSS and closed source software ...Employed full-timeUnited StatesNoBachelor’s degree (BA, BS, B.Eng., etc.)Computer science, computer engineering, or sof...Taken an online course in programming or softw...100 to 499 employeesDeveloper, full-stack316Less than 1 yearVery satisfiedSlightly satisfiedVery confidentNoNot sureI am not interested in new job opportunitiesLess than a year agoWrite code by hand (e.g., on a whiteboard);Int...NoLanguages, frameworks, and other technologies ...I was preparing for a job searchUSDUnited States dollar61000.0Yearly61000.080.0There's no schedule or spec; I work on what se...NaNLess than once per month / NeverHomeA little below averageNoNaNNo, but I think we shouldDevelopers typically have the most influence o...I have little or no influenceC;C++;C#;Python;SQLC;C#;JavaScript;SQLMySQL;SQLiteMySQL;SQLiteLinux;WindowsLinux;WindowsNaNNaN.NET.NETEclipse;Vim;Visual Studio;Visual Studio CodeWindowsI do not use containersNot at allUseful for decentralized currency (i.e., Bitcoin)YesSIGHYesRedditIn real life (in person)Username2014Daily or almost dailyFind answers to specific questions;Pass the ti...1-2 times per weekStack Overflow was much faster31-60 minutesYesLess than once per month or monthlyYesNo, and I don't know what those areNo, not reallyJust as welcome now as I felt last yearTech articles written by other developers;Indu...22.0ManNoStraight / HeterosexualWhite or of European descentNoAppropriate in lengthEasy
5I am a developer by professionYesOnce a month or more oftenOSS is, on average, of HIGHER quality than pro...Employed full-timeUkraineNoBachelor’s degree (BA, BS, B.Eng., etc.)Computer science, computer engineering, or sof...Taken an online course in programming or softw...10,000 or more employeesAcademic researcher;Developer, desktop or ente...16149Very dissatisfiedSlightly dissatisfiedSomewhat confidentYesNoI am not interested in new job opportunitiesLess than a year agoWrite any code;Write code by hand (e.g., on a ...NoIndustry that I'd be working in;Languages, fra...I was preparing for a job searchUAHUkrainian hryvniaNaNNaNNaN55.0There is a schedule and/or spec (made by me or...Being tasked with non-development work;Inadequ...A few days each monthOfficeA little above averageYes, because I see value in code reviewNaNYes, it's part of our processNot sureI have little or no influenceC++;HTML/CSS;Java;JavaScript;Python;SQL;VBAHTML/CSS;Java;JavaScript;SQL;WebAssemblyCouchbase;MongoDB;MySQL;Oracle;PostgreSQL;SQLiteCouchbase;Firebase;MongoDB;MySQL;Oracle;Postgr...Android;Linux;MacOS;Slack;WindowsAndroid;Docker;Kubernetes;Linux;SlackDjango;Express;Flask;jQuery;React.js;SpringFlask;jQuery;React.js;SpringCordova;Node.jsApache Spark;Hadoop;Node.js;React NativeIntelliJ;Notepad++;VimLinux-basedOutside of work, for personal projectsNot at allNaNYesAlso YesYesFacebookIn real life (in person)UsernameI don't rememberMultiple times per dayFind answers to specific questionsMore than 10 times per weekStack Overflow was much fasterNaNYesA few times per month or weeklyNo, I knew that Stack Overflow had a job board...No, I've heard of them, but I am not part of a...Yes, definitelyJust as welcome now as I felt last yearTech meetups or events in your area;Courses on...30.0ManNoStraight / HeterosexualWhite or of European descent;MultiracialNoAppropriate in lengthEasy
df.loc[1]
MainBranch                           I am a student who is learning to code
Hobbyist                                                                Yes
OpenSourcer                                                           Never
OpenSource                The quality of OSS and closed source software ...
Employment                           Not employed, and not looking for work
Country                                                      United Kingdom
Student                                                                  No
EdLevel                                           Primary/elementary school
UndergradMajor                                                          NaN
EduOther                  Taught yourself a new language, framework, or ...
OrgSize                                                                 NaN
DevType                                                                 NaN
YearsCode                                                                 4
Age1stCode                                                               10
YearsCodePro                                                            NaN
CareerSat                                                               NaN
JobSat                                                                  NaN
MgrIdiot                                                                NaN
MgrMoney                                                                NaN
MgrWant                                                                 NaN
JobSeek                                                                 NaN
LastHireDate                                                            NaN
LastInt                                                                 NaN
FizzBuzz                                                                NaN
JobFactors                                                              NaN
ResumeUpdate                                                            NaN
CurrencySymbol                                                          NaN
CurrencyDesc                                                            NaN
CompTotal                                                               NaN
CompFreq                                                                NaN
ConvertedComp                                                           NaN
WorkWeekHrs                                                             NaN
WorkPlan                                                                NaN
WorkChallenge                                                           NaN
WorkRemote                                                              NaN
WorkLoc                                                                 NaN
ImpSyn                                                                  NaN
CodeRev                                                                 NaN
CodeRevHrs                                                              NaN
UnitTests                                                               NaN
PurchaseHow                                                             NaN
PurchaseWhat                                                            NaN
LanguageWorkedWith                          HTML/CSS;Java;JavaScript;Python
LanguageDesireNextYear      C;C++;C#;Go;HTML/CSS;Java;JavaScript;Python;SQL
DatabaseWorkedWith                                                   SQLite
DatabaseDesireNextYear                                                MySQL
PlatformWorkedWith                                            MacOS;Windows
PlatformDesireNextYear                              Android;Arduino;Windows
WebFrameWorkedWith                                             Django;Flask
WebFrameDesireNextYear                                         Flask;jQuery
MiscTechWorkedWith                                                  Node.js
MiscTechDesireNextYear                                              Node.js
DevEnviron                                       IntelliJ;Notepad++;PyCharm
OpSys                                                               Windows
Containers                                          I do not use containers
BlockchainOrg                                                           NaN
BlockchainIs                                                            NaN
BetterLife                                                              Yes
ITperson                           Fortunately, someone else has that title
OffOn                                                                   Yes
SocialMedia                                                         Twitter
Extraversion                                                         Online
ScreenName                                                         Username
SOVisit1st                                                             2017
SOVisitFreq                                 A few times per month or weekly
SOVisitTo                 Find answers to specific questions;Learn how t...
SOFindAnswer                                             3-5 times per week
SOTimeSaved                                  Stack Overflow was much faster
SOHowMuchTime                                                 31-60 minutes
SOAccount                                                                No
SOPartFreq                                                              NaN
SOJobs                    No, I didn't know that Stack Overflow had a jo...
EntTeams                                No, and I don't know what those are
SOComm                                                              Neutral
WelcomeChange                       Just as welcome now as I felt last year
SONewContent              Tech articles written by other developers;Indu...
Age                                                                    14.0
Gender                                                                  Man
Trans                                                                    No
Sexuality                                           Straight / Heterosexual
Ethnicity                                                               NaN
Dependents                                                               No
SurveyLength                                          Appropriate in length
SurveyEase                                       Neither easy nor difficult
Name: 1, dtype: object

df.iloc根据位置返回值,df.loc根据索引返回值,df.iloc[0]与df.loc[1]返回的结果一致

获取变量的含义

schema_df = pd.read_csv('data/survey_results_schema.csv',index_col='Column')
schema_df
QuestionText
Column
RespondentRandomized respondent ID number (not in order ...
MainBranchWhich of the following options best describes ...
HobbyistDo you code as a hobby?
OpenSourcerHow often do you contribute to open source?
OpenSourceHow do you feel about the quality of open sour...
EmploymentWhich of the following best describes your cur...
CountryIn which country do you currently reside?
StudentAre you currently enrolled in a formal, degree...
EdLevelWhich of the following best describes the high...
UndergradMajorWhat was your main or most important field of ...
EduOtherWhich of the following types of non-degree edu...
OrgSizeApproximately how many people are employed by ...
DevTypeWhich of the following describe you? Please se...
YearsCodeIncluding any education, how many years have y...
Age1stCodeAt what age did you write your first line of c...
YearsCodeProHow many years have you coded professionally (...
CareerSatOverall, how satisfied are you with your caree...
JobSatHow satisfied are you with your current job? (...
MgrIdiotHow confident are you that your manager knows ...
MgrMoneyDo you believe that you need to be a manager t...
MgrWantDo you want to become a manager yourself in th...
JobSeekWhich of the following best describes your cur...
LastHireDateWhen was the last time that you took a job wit...
LastIntIn your most recent successful job interview (...
FizzBuzzHave you ever been asked to solve FizzBuzz in ...
JobFactorsImagine that you are deciding between two job ...
ResumeUpdateThink back to the last time you updated your r...
CurrencySymbolWhich currency do you use day-to-day? If your ...
CurrencyDescWhich currency do you use day-to-day? If your ...
CompTotalWhat is your current total compensation (salar...
CompFreqIs that compensation weekly, monthly, or yearly?
ConvertedCompSalary converted to annual USD salaries using ...
WorkWeekHrsOn average, how many hours per week do you work?
WorkPlanHow structured or planned is your work?
WorkChallengeOf these options, what are your greatest chall...
WorkRemoteHow often do you work remotely?
WorkLocWhere would you prefer to work?
ImpSynFor the specific work you do, and the years of...
CodeRevDo you review code as part of your work?
CodeRevHrsOn average, how many hours per week do you spe...
UnitTestsDoes your company regularly employ unit tests ...
PurchaseHowHow does your company make decisions about pur...
PurchaseWhatWhat level of influence do you, personally, ha...
LanguageWorkedWithWhich of the following programming, scripting,...
LanguageDesireNextYearWhich of the following programming, scripting,...
DatabaseWorkedWithWhich of the following database environments h...
DatabaseDesireNextYearWhich of the following database environments h...
PlatformWorkedWithWhich of the following platforms have you done...
PlatformDesireNextYearWhich of the following platforms have you done...
WebFrameWorkedWithWhich of the following web frameworks have you...
WebFrameDesireNextYearWhich of the following web frameworks have you...
MiscTechWorkedWithWhich of the following other frameworks, libra...
MiscTechDesireNextYearWhich of the following other frameworks, libra...
DevEnvironWhich development environment(s) do you use re...
OpSysWhat is the primary operating system in which ...
ContainersHow do you use containers (Docker, Open Contai...
BlockchainOrgHow is your organization thinking about or imp...
BlockchainIsBlockchain / cryptocurrency technology is prim...
BetterLifeDo you think people born today will have a bet...
ITpersonAre you the "IT support person" for your family?
OffOnHave you tried turning it off and on again?
SocialMediaWhat social media site do you use the most?
ExtraversionDo you prefer online chat or IRL conversations?
ScreenNameWhat do you call it?
SOVisit1stTo the best of your memory, when did you first...
SOVisitFreqHow frequently would you say you visit Stack O...
SOVisitToI visit Stack Overflow to... (check all that a...
SOFindAnswerOn average, how many times a week do you find ...
SOTimeSavedThink back to the last time you solved a codin...
SOHowMuchTimeAbout how much time did you save? If you're no...
SOAccountDo you have a Stack Overflow account?
SOPartFreqHow frequently would you say you participate i...
SOJobsHave you ever used or visited Stack Overflow J...
EntTeamsHave you ever used Stack Overflow for Enterpri...
SOCommDo you consider yourself a member of the Stack...
WelcomeChangeCompared to last year, how welcome do you feel...
SONewContentWould you like to see any of the following on ...
AgeWhat is your age (in years)? If you prefer not...
GenderWhich of the following do you currently identi...
TransDo you identify as transgender?
SexualityWhich of the following do you currently identi...
EthnicityWhich of the following do you identify as? Ple...
DependentsDo you have any dependents (e.g., children, el...
SurveyLengthHow do you feel about the length of the survey...
SurveyEaseHow easy or difficult was this survey to compl...
schema_df.loc['Hobbyist']
QuestionText    Do you code as a hobby?
Name: Hobbyist, dtype: object
schema_df.loc['Hobbyist','QuestionText']
'Do you code as a hobby?'

按照索引排序

  • 按照索引排序(默认按照字母顺序升序)
schema_df.sort_index()#如果降序使用schema_df.sort_index(ascending=False),同样也可使用inplace=True
QuestionText
Column
AgeWhat is your age (in years)? If you prefer not...
Age1stCodeAt what age did you write your first line of c...
BetterLifeDo you think people born today will have a bet...
BlockchainIsBlockchain / cryptocurrency technology is prim...
BlockchainOrgHow is your organization thinking about or imp...
CareerSatOverall, how satisfied are you with your caree...
CodeRevDo you review code as part of your work?
CodeRevHrsOn average, how many hours per week do you spe...
CompFreqIs that compensation weekly, monthly, or yearly?
CompTotalWhat is your current total compensation (salar...
ContainersHow do you use containers (Docker, Open Contai...
ConvertedCompSalary converted to annual USD salaries using ...
CountryIn which country do you currently reside?
CurrencyDescWhich currency do you use day-to-day? If your ...
CurrencySymbolWhich currency do you use day-to-day? If your ...
DatabaseDesireNextYearWhich of the following database environments h...
DatabaseWorkedWithWhich of the following database environments h...
DependentsDo you have any dependents (e.g., children, el...
DevEnvironWhich development environment(s) do you use re...
DevTypeWhich of the following describe you? Please se...
EdLevelWhich of the following best describes the high...
EduOtherWhich of the following types of non-degree edu...
EmploymentWhich of the following best describes your cur...
EntTeamsHave you ever used Stack Overflow for Enterpri...
EthnicityWhich of the following do you identify as? Ple...
ExtraversionDo you prefer online chat or IRL conversations?
FizzBuzzHave you ever been asked to solve FizzBuzz in ...
GenderWhich of the following do you currently identi...
HobbyistDo you code as a hobby?
ITpersonAre you the "IT support person" for your family?
ImpSynFor the specific work you do, and the years of...
JobFactorsImagine that you are deciding between two job ...
JobSatHow satisfied are you with your current job? (...
JobSeekWhich of the following best describes your cur...
LanguageDesireNextYearWhich of the following programming, scripting,...
LanguageWorkedWithWhich of the following programming, scripting,...
LastHireDateWhen was the last time that you took a job wit...
LastIntIn your most recent successful job interview (...
MainBranchWhich of the following options best describes ...
MgrIdiotHow confident are you that your manager knows ...
MgrMoneyDo you believe that you need to be a manager t...
MgrWantDo you want to become a manager yourself in th...
MiscTechDesireNextYearWhich of the following other frameworks, libra...
MiscTechWorkedWithWhich of the following other frameworks, libra...
OffOnHave you tried turning it off and on again?
OpSysWhat is the primary operating system in which ...
OpenSourceHow do you feel about the quality of open sour...
OpenSourcerHow often do you contribute to open source?
OrgSizeApproximately how many people are employed by ...
PlatformDesireNextYearWhich of the following platforms have you done...
PlatformWorkedWithWhich of the following platforms have you done...
PurchaseHowHow does your company make decisions about pur...
PurchaseWhatWhat level of influence do you, personally, ha...
RespondentRandomized respondent ID number (not in order ...
ResumeUpdateThink back to the last time you updated your r...
SOAccountDo you have a Stack Overflow account?
SOCommDo you consider yourself a member of the Stack...
SOFindAnswerOn average, how many times a week do you find ...
SOHowMuchTimeAbout how much time did you save? If you're no...
SOJobsHave you ever used or visited Stack Overflow J...
SONewContentWould you like to see any of the following on ...
SOPartFreqHow frequently would you say you participate i...
SOTimeSavedThink back to the last time you solved a codin...
SOVisit1stTo the best of your memory, when did you first...
SOVisitFreqHow frequently would you say you visit Stack O...
SOVisitToI visit Stack Overflow to... (check all that a...
ScreenNameWhat do you call it?
SexualityWhich of the following do you currently identi...
SocialMediaWhat social media site do you use the most?
StudentAre you currently enrolled in a formal, degree...
SurveyEaseHow easy or difficult was this survey to compl...
SurveyLengthHow do you feel about the length of the survey...
TransDo you identify as transgender?
UndergradMajorWhat was your main or most important field of ...
UnitTestsDoes your company regularly employ unit tests ...
WebFrameDesireNextYearWhich of the following web frameworks have you...
WebFrameWorkedWithWhich of the following web frameworks have you...
WelcomeChangeCompared to last year, how welcome do you feel...
WorkChallengeOf these options, what are your greatest chall...
WorkLocWhere would you prefer to work?
WorkPlanHow structured or planned is your work?
WorkRemoteHow often do you work remotely?
WorkWeekHrsOn average, how many hours per week do you work?
YearsCodeIncluding any education, how many years have y...
YearsCodeProHow many years have you coded professionally (...

筛选

people = {
    "first": ["Corey", 'Jane', 'John'], 
    "last": ["Schafer", 'Doe', 'Doe'], 
    "email": ["CoreyMSchafer@gmail", 'JaneDoe@email', 'JohnDoe@email']
}
import pandas as pd
df = pd.DataFrame(people)
df
firstlastemail
0CoreySchaferCoreyMSchafer@gmail
1JaneDoeJaneDoe@email
2JohnDoeJohnDoe@email
df['last'] == 'Doe'
0    False
1     True
2     True
Name: last, dtype: bool
filt = (df['last'] == 'Doe')
df[filt]
firstlastemail
1JaneDoeJaneDoe@email
2JohnDoeJohnDoe@email
df[df['last'] == 'Doe']
firstlastemail
1JaneDoeJaneDoe@email
2JohnDoeJohnDoe@email

这种写法也可以

df.loc[filt]
firstlastemail
1JaneDoeJaneDoe@email
2JohnDoeJohnDoe@email

df.loc与df[filt]结果返回一样,df.loc更方便的一点是还可以继续访问列

df.loc[filt,'email']
1    JaneDoe@email
2    JohnDoe@email
Name: email, dtype: object

与或非

Pandas与Python内置函数不同不使用and和or,而使用&或者|

df
firstlastemail
0CoreySchaferCoreyMSchafer@gmail
1JaneDoeJaneDoe@email
2JohnDoeJohnDoe@email
filt = (df['last'] == 'Doe') & (df['first'] == 'John')
df.loc[filt,'email']
2    JohnDoe@email
Name: email, dtype: object

df
firstlastemail
0CoreySchaferCoreyMSchafer@gmail
1JaneDoeJaneDoe@email
2JohnDoeJohnDoe@email
filt = (df['last'] == 'Schafer') | (df['first'] == 'John')
df.loc[filt,'email']
0    CoreyMSchafer@gmail
2          JohnDoe@email
Name: email, dtype: object

df
firstlastemail
0CoreySchaferCoreyMSchafer@gmail
1JaneDoeJaneDoe@email
2JohnDoeJohnDoe@email
df.loc[-filt,'email']
1    JaneDoe@email
Name: email, dtype: object

df = pd.read_csv('data/survey_results_public.csv',index_col='Respondent')
pd.set_option('display.max_columns', 85)
pd.set_option('display.max_rows', 85)
df.head()
MainBranchHobbyistOpenSourcerOpenSourceEmploymentCountryStudentEdLevelUndergradMajorEduOtherOrgSizeDevTypeYearsCodeAge1stCodeYearsCodeProCareerSatJobSatMgrIdiotMgrMoneyMgrWantJobSeekLastHireDateLastIntFizzBuzzJobFactorsResumeUpdateCurrencySymbolCurrencyDescCompTotalCompFreqConvertedCompWorkWeekHrsWorkPlanWorkChallengeWorkRemoteWorkLocImpSynCodeRevCodeRevHrsUnitTestsPurchaseHowPurchaseWhatLanguageWorkedWithLanguageDesireNextYearDatabaseWorkedWithDatabaseDesireNextYearPlatformWorkedWithPlatformDesireNextYearWebFrameWorkedWithWebFrameDesireNextYearMiscTechWorkedWithMiscTechDesireNextYearDevEnvironOpSysContainersBlockchainOrgBlockchainIsBetterLifeITpersonOffOnSocialMediaExtraversionScreenNameSOVisit1stSOVisitFreqSOVisitToSOFindAnswerSOTimeSavedSOHowMuchTimeSOAccountSOPartFreqSOJobsEntTeamsSOCommWelcomeChangeSONewContentAgeGenderTransSexualityEthnicityDependentsSurveyLengthSurveyEase
Respondent
1I am a student who is learning to codeYesNeverThe quality of OSS and closed source software ...Not employed, and not looking for workUnited KingdomNoPrimary/elementary schoolNaNTaught yourself a new language, framework, or ...NaNNaN410NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNHTML/CSS;Java;JavaScript;PythonC;C++;C#;Go;HTML/CSS;Java;JavaScript;Python;SQLSQLiteMySQLMacOS;WindowsAndroid;Arduino;WindowsDjango;FlaskFlask;jQueryNode.jsNode.jsIntelliJ;Notepad++;PyCharmWindowsI do not use containersNaNNaNYesFortunately, someone else has that titleYesTwitterOnlineUsername2017A few times per month or weeklyFind answers to specific questions;Learn how t...3-5 times per weekStack Overflow was much faster31-60 minutesNoNaNNo, I didn't know that Stack Overflow had a jo...No, and I don't know what those areNeutralJust as welcome now as I felt last yearTech articles written by other developers;Indu...14.0ManNoStraight / HeterosexualNaNNoAppropriate in lengthNeither easy nor difficult
2I am a student who is learning to codeNoLess than once per yearThe quality of OSS and closed source software ...Not employed, but looking for workBosnia and HerzegovinaYes, full-timeSecondary school (e.g. American high school, G...NaNTaken an online course in programming or softw...NaNDeveloper, desktop or enterprise applications;...NaN17NaNNaNNaNNaNNaNNaNI am actively looking for a jobI've never had a jobNaNNaNFinancial performance or funding status of the...Something else changed (education, award, medi...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNC++;HTML/CSS;PythonC++;HTML/CSS;JavaScript;SQLNaNMySQLWindowsWindowsDjangoDjangoNaNNaNAtom;PyCharmWindowsI do not use containersNaNUseful across many domains and could change ma...YesYesYesInstagramOnlineUsername2017Daily or almost dailyFind answers to specific questions;Learn how t...3-5 times per weekStack Overflow was much faster11-30 minutesYesA few times per month or weeklyNo, I knew that Stack Overflow had a job board...No, and I don't know what those areYes, somewhatJust as welcome now as I felt last yearTech articles written by other developers;Indu...19.0ManNoStraight / HeterosexualNaNNoAppropriate in lengthNeither easy nor difficult
3I am not primarily a developer, but I write co...YesNeverThe quality of OSS and closed source software ...Employed full-timeThailandNoBachelor’s degree (BA, BS, B.Eng., etc.)Web development or web designTaught yourself a new language, framework, or ...100 to 499 employeesDesigner;Developer, back-end;Developer, front-...3221Slightly satisfiedSlightly satisfiedNot at all confidentNot sureNot sureI’m not actively looking, but I am open to new...1-2 years agoInterview with people in peer rolesNoLanguages, frameworks, and other technologies ...I was preparing for a job searchTHBThai baht23000.0Monthly8820.040.0There's no schedule or spec; I work on what se...Distracting work environment;Inadequate access...Less than once per month / NeverHomeAverageNoNaNNo, but I think we shouldNot sureI have little or no influenceHTML/CSSElixir;HTML/CSSPostgreSQLPostgreSQLNaNNaNNaNOther(s):NaNNaNVim;Visual Studio CodeLinux-basedI do not use containersNaNNaNYesYesYesRedditIn real life (in person)Username2011A few times per weekFind answers to specific questions;Learn how t...6-10 times per weekThey were about the sameNaNYesLess than once per month or monthlyYesNo, I've heard of them, but I am not part of a...NeutralJust as welcome now as I felt last yearTech meetups or events in your area;Courses on...28.0ManNoStraight / HeterosexualNaNYesAppropriate in lengthNeither easy nor difficult
4I am a developer by professionNoNeverThe quality of OSS and closed source software ...Employed full-timeUnited StatesNoBachelor’s degree (BA, BS, B.Eng., etc.)Computer science, computer engineering, or sof...Taken an online course in programming or softw...100 to 499 employeesDeveloper, full-stack316Less than 1 yearVery satisfiedSlightly satisfiedVery confidentNoNot sureI am not interested in new job opportunitiesLess than a year agoWrite code by hand (e.g., on a whiteboard);Int...NoLanguages, frameworks, and other technologies ...I was preparing for a job searchUSDUnited States dollar61000.0Yearly61000.080.0There's no schedule or spec; I work on what se...NaNLess than once per month / NeverHomeA little below averageNoNaNNo, but I think we shouldDevelopers typically have the most influence o...I have little or no influenceC;C++;C#;Python;SQLC;C#;JavaScript;SQLMySQL;SQLiteMySQL;SQLiteLinux;WindowsLinux;WindowsNaNNaN.NET.NETEclipse;Vim;Visual Studio;Visual Studio CodeWindowsI do not use containersNot at allUseful for decentralized currency (i.e., Bitcoin)YesSIGHYesRedditIn real life (in person)Username2014Daily or almost dailyFind answers to specific questions;Pass the ti...1-2 times per weekStack Overflow was much faster31-60 minutesYesLess than once per month or monthlyYesNo, and I don't know what those areNo, not reallyJust as welcome now as I felt last yearTech articles written by other developers;Indu...22.0ManNoStraight / HeterosexualWhite or of European descentNoAppropriate in lengthEasy
5I am a developer by professionYesOnce a month or more oftenOSS is, on average, of HIGHER quality than pro...Employed full-timeUkraineNoBachelor’s degree (BA, BS, B.Eng., etc.)Computer science, computer engineering, or sof...Taken an online course in programming or softw...10,000 or more employeesAcademic researcher;Developer, desktop or ente...16149Very dissatisfiedSlightly dissatisfiedSomewhat confidentYesNoI am not interested in new job opportunitiesLess than a year agoWrite any code;Write code by hand (e.g., on a ...NoIndustry that I'd be working in;Languages, fra...I was preparing for a job searchUAHUkrainian hryvniaNaNNaNNaN55.0There is a schedule and/or spec (made by me or...Being tasked with non-development work;Inadequ...A few days each monthOfficeA little above averageYes, because I see value in code reviewNaNYes, it's part of our processNot sureI have little or no influenceC++;HTML/CSS;Java;JavaScript;Python;SQL;VBAHTML/CSS;Java;JavaScript;SQL;WebAssemblyCouchbase;MongoDB;MySQL;Oracle;PostgreSQL;SQLiteCouchbase;Firebase;MongoDB;MySQL;Oracle;Postgr...Android;Linux;MacOS;Slack;WindowsAndroid;Docker;Kubernetes;Linux;SlackDjango;Express;Flask;jQuery;React.js;SpringFlask;jQuery;React.js;SpringCordova;Node.jsApache Spark;Hadoop;Node.js;React NativeIntelliJ;Notepad++;VimLinux-basedOutside of work, for personal projectsNot at allNaNYesAlso YesYesFacebookIn real life (in person)UsernameI don't rememberMultiple times per dayFind answers to specific questionsMore than 10 times per weekStack Overflow was much fasterNaNYesA few times per month or weeklyNo, I knew that Stack Overflow had a job board...No, I've heard of them, but I am not part of a...Yes, definitelyJust as welcome now as I felt last yearTech meetups or events in your area;Courses on...30.0ManNoStraight / HeterosexualWhite or of European descent;MultiracialNoAppropriate in lengthEasy

例子

  1. 查找高薪数据
high_salary = (df['ConvertedComp'] > 70000)
df.loc[high_salary,['Country','LanguageWorkedWith','ConvertedComp']]
CountryLanguageWorkedWithConvertedComp
Respondent
6CanadaJava;R;SQL366420.0
9New ZealandBash/Shell/PowerShell;C#;HTML/CSS;JavaScript;P...95179.0
13United StatesBash/Shell/PowerShell;HTML/CSS;JavaScript;PHP;...90000.0
16United KingdomBash/Shell/PowerShell;C#;HTML/CSS;JavaScript;T...455352.0
22United StatesBash/Shell/PowerShell;C++;HTML/CSS;JavaScript;...103000.0
............
88876United StatesBash/Shell/PowerShell;C#;HTML/CSS;Java;Python;...180000.0
88877United StatesBash/Shell/PowerShell;C;Clojure;HTML/CSS;Java;...2000000.0
88878United StatesHTML/CSS;JavaScript;Scala;TypeScript130000.0
88879FinlandBash/Shell/PowerShell;C++;Python82488.0
88882NetherlandsC#;HTML/CSS;Java;JavaScript;PHP;Python588012.0

22289 rows × 3 columns

  1. 查找国家是United States’,‘India’,‘United Kingom’,‘German’,'Canada’的数据
coutries = ['United States','India','United Kingom','German','Canada']
filt = df['Country'].isin(coutries)
df.loc[filt,'Country']
Respondent
4        United States
6               Canada
8                India
10               India
12              Canada
             ...      
85182           Canada
85642    United States
86012            India
88282    United States
88377           Canada
Name: Country, Length: 33405, dtype: object
  1. 查找LanguageWorkedWith包含python数据
filt = df['LanguageWorkedWith'].str.contains('Python',na=False)
df.loc[filt,'LanguageWorkedWith']
Respondent
1                          HTML/CSS;Java;JavaScript;Python
2                                      C++;HTML/CSS;Python
4                                      C;C++;C#;Python;SQL
5              C++;HTML/CSS;Java;JavaScript;Python;SQL;VBA
8        Bash/Shell/PowerShell;C;C++;HTML/CSS;Java;Java...
                               ...                        
84539    Bash/Shell/PowerShell;C;C++;HTML/CSS;Java;Java...
85738      Bash/Shell/PowerShell;C++;Python;Ruby;Other(s):
86566      Bash/Shell/PowerShell;HTML/CSS;Python;Other(s):
87739             C;C++;HTML/CSS;JavaScript;PHP;Python;SQL
88212                           HTML/CSS;JavaScript;Python
Name: LanguageWorkedWith, Length: 36443, dtype: object

更改数据

people = {
    "first": ["Corey", 'Jane', 'John'], 
    "last": ["Schafer", 'Doe', 'Doe'], 
    "email": ["CoreyMSchafer@gmail", 'JaneDoe@email', 'JohnDoe@email']
}
import pandas as pd
df = pd.DataFrame(people)
df
firstlastemail
0CoreySchaferCoreyMSchafer@gmail
1JaneDoeJaneDoe@email
2JohnDoeJohnDoe@email
df.columns
Index(['first', 'last', 'email'], dtype='object')

更新列名

df.columns = ['first_name','last_name','email']
df
first_namelast_nameemail
0CoreySchaferCoreyMSchafer@gmail
1JaneDoeJaneDoe@email
2JohnDoeJohnDoe@email
  • 将列名改为大写
df.columns = [x.upper() for x in df.columns]
df
FIRST_NAMELAST_NAMEEMAIL
0CoreySchaferCoreyMSchafer@gmail
1JaneDoeJaneDoe@email
2JohnDoeJohnDoe@email
  • 下滑线改为空格
df.columns = df.columns.str.replace('_',' ')
df
FIRST NAMELAST NAMEEMAIL
0CoreySchaferCoreyMSchafer@gmail
1JaneDoeJaneDoe@email
2JohnDoeJohnDoe@email
df.columns = ['first_name','last_name','email']
df
first_namelast_nameemail
0CoreySchaferCoreyMSchafer@gmail
1JaneDoeJaneDoe@email
2JohnDoeJohnDoe@email
  • rename方法
df.rename(columns={'first_name':'first','last_name':'last'},inplace=True)
df
firstlastemail
0CoreySchaferCoreyMSchafer@gmail
1JaneDoeJaneDoe@email
2JohnDoeJohnDoe@email

更新数据

df.loc[2] = ['John','Smith','JohnSmith@email']
df
firstlastemail
0CoreySchaferCoreyMSchafer@gmail
1JaneDoeJaneDoe@email
2JohnSmithJohnSmith@email

如果这个数据有85列,这种修改数据方法的方法将很麻烦

df.loc[2,['last','email']] = ['Doe','JohnDoe@email']
df                              
firstlastemail
0CoreySchaferCoreyMSchafer@gmail
1JaneDoeJaneDoe@email
2JohnDoeJohnDoe@email
df.loc[2,'last'] = 'Smith'
df
firstlastemail
0CoreySchaferCoreyMSchafer@gmail
1JaneDoeJaneDoe@email
2JohnSmithJohnDoe@email
df.loc[2,'last'] = 'Doe'
df
firstlastemail
0CoreySchaferCoreyMSchafer@gmail
1JaneDoeJaneDoe@email
2JohnDoeJohnDoe@email
filt = (df['email']=='JohnDoe@email')
df.loc[filt,'last'] = 'Smith'
df
firstlastemail
0CoreySchaferCoreyMSchafer@gmail
1JaneDoeJaneDoe@email
2JohnSmithJohnDoe@email

df[filt,‘last’] = 'Smith’是错误的,因为他不可以选择列

  • email列数据改成小写
df['email'].str.lower()
0    coreymschafer@gmail
1          janedoe@email
2          johndoe@email
Name: email, dtype: object
df['email'] = df['email'].str.lower()
df
firstlastemail
0CoreySchafercoreymschafer@gmail
1JaneDoejanedoe@email
2JohnSmithjohndoe@email

apply

df['email'].apply(len)
0    23
1    17
2    17
Name: email, dtype: int64
def update_email(email):
    return email.upper()
df['email'].apply(update_email)
0    COREYMSCHAFER@GMAIL.COM
1          JANEDOE@EMAIL.COM
2          JOHNDOE@EMAIL.COM
Name: email, dtype: object
df['email'] = df['email'].apply(update_email)
df
firstlastemail
0CoreySchaferCOREYMSCHAFER@GMAIL.COM
1JaneDoeJANEDOE@EMAIL.COM
2JohnSmithJOHNDOE@EMAIL.COM
df['email'] = df['email'].apply(lambda x: x.lower())
df
firstlastemail
0CoreySchafercoreymschafer@gmail
1JaneDoejanedoe@email
2JohnSmithjohndoe@email
  • 传入的函数不需要带括号
  • 不太复杂时用lambda
  • 复杂时,自定义函数
df.apply(len)
first    3
last     3
email    3
dtype: int64
df.apply(len,axis='columns')
0    3
1    3
2    3
dtype: int64
df.apply(pd.Series.min)
first                      Corey
last                         Doe
email    coreymschafer@gmail
dtype: object
df.apply(lambda x:x.min())
first                      Corey
last                         Doe
email    coreymschafer@gmail
dtype: object

applymap

  • 数据框的每个元素应用len
df.applymap(len)
firstlastemail
05723
14317
24517
df.applymap(str.lower)
firstlastemail
0coreyschafercoreymschafer@gmail
1janedoejanedoe@email
2johnsmithjohndoe@email

map

df
firstlastemail
0CoreySchafercoreymschafer@gmail
1JaneDoejanedoe@email
2JohnSmithjohndoe@email
df['first'].map({'Corey':'Chris','Jane':'Mary'})
0    Chris
1     Mary
2      NaN
Name: first, dtype: object

其他位置被替换成了空值,与自己的目的相违背,我们可以采用replace函数

replace

df['first'].replace({'Corey':'Chris','Jane':'Mary'})
0    Chris
1     Mary
2     John
Name: first, dtype: object

df = pd.read_csv('data/survey_results_public.csv',index_col='Respondent')
pd.set_option('display.max_columns', 85)
pd.set_option('display.max_rows', 85)
df.head()
MainBranchHobbyistOpenSourcerOpenSourceEmploymentCountryStudentEdLevelUndergradMajorEduOtherOrgSizeDevTypeYearsCodeAge1stCodeYearsCodeProCareerSatJobSatMgrIdiotMgrMoneyMgrWantJobSeekLastHireDateLastIntFizzBuzzJobFactorsResumeUpdateCurrencySymbolCurrencyDescCompTotalCompFreqConvertedCompWorkWeekHrsWorkPlanWorkChallengeWorkRemoteWorkLocImpSynCodeRevCodeRevHrsUnitTestsPurchaseHowPurchaseWhatLanguageWorkedWithLanguageDesireNextYearDatabaseWorkedWithDatabaseDesireNextYearPlatformWorkedWithPlatformDesireNextYearWebFrameWorkedWithWebFrameDesireNextYearMiscTechWorkedWithMiscTechDesireNextYearDevEnvironOpSysContainersBlockchainOrgBlockchainIsBetterLifeITpersonOffOnSocialMediaExtraversionScreenNameSOVisit1stSOVisitFreqSOVisitToSOFindAnswerSOTimeSavedSOHowMuchTimeSOAccountSOPartFreqSOJobsEntTeamsSOCommWelcomeChangeSONewContentAgeGenderTransSexualityEthnicityDependentsSurveyLengthSurveyEase
Respondent
1I am a student who is learning to codeYesNeverThe quality of OSS and closed source software ...Not employed, and not looking for workUnited KingdomNoPrimary/elementary schoolNaNTaught yourself a new language, framework, or ...NaNNaN410NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNHTML/CSS;Java;JavaScript;PythonC;C++;C#;Go;HTML/CSS;Java;JavaScript;Python;SQLSQLiteMySQLMacOS;WindowsAndroid;Arduino;WindowsDjango;FlaskFlask;jQueryNode.jsNode.jsIntelliJ;Notepad++;PyCharmWindowsI do not use containersNaNNaNYesFortunately, someone else has that titleYesTwitterOnlineUsername2017A few times per month or weeklyFind answers to specific questions;Learn how t...3-5 times per weekStack Overflow was much faster31-60 minutesNoNaNNo, I didn't know that Stack Overflow had a jo...No, and I don't know what those areNeutralJust as welcome now as I felt last yearTech articles written by other developers;Indu...14.0ManNoStraight / HeterosexualNaNNoAppropriate in lengthNeither easy nor difficult
2I am a student who is learning to codeNoLess than once per yearThe quality of OSS and closed source software ...Not employed, but looking for workBosnia and HerzegovinaYes, full-timeSecondary school (e.g. American high school, G...NaNTaken an online course in programming or softw...NaNDeveloper, desktop or enterprise applications;...NaN17NaNNaNNaNNaNNaNNaNI am actively looking for a jobI've never had a jobNaNNaNFinancial performance or funding status of the...Something else changed (education, award, medi...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNC++;HTML/CSS;PythonC++;HTML/CSS;JavaScript;SQLNaNMySQLWindowsWindowsDjangoDjangoNaNNaNAtom;PyCharmWindowsI do not use containersNaNUseful across many domains and could change ma...YesYesYesInstagramOnlineUsername2017Daily or almost dailyFind answers to specific questions;Learn how t...3-5 times per weekStack Overflow was much faster11-30 minutesYesA few times per month or weeklyNo, I knew that Stack Overflow had a job board...No, and I don't know what those areYes, somewhatJust as welcome now as I felt last yearTech articles written by other developers;Indu...19.0ManNoStraight / HeterosexualNaNNoAppropriate in lengthNeither easy nor difficult
3I am not primarily a developer, but I write co...YesNeverThe quality of OSS and closed source software ...Employed full-timeThailandNoBachelor’s degree (BA, BS, B.Eng., etc.)Web development or web designTaught yourself a new language, framework, or ...100 to 499 employeesDesigner;Developer, back-end;Developer, front-...3221Slightly satisfiedSlightly satisfiedNot at all confidentNot sureNot sureI’m not actively looking, but I am open to new...1-2 years agoInterview with people in peer rolesNoLanguages, frameworks, and other technologies ...I was preparing for a job searchTHBThai baht23000.0Monthly8820.040.0There's no schedule or spec; I work on what se...Distracting work environment;Inadequate access...Less than once per month / NeverHomeAverageNoNaNNo, but I think we shouldNot sureI have little or no influenceHTML/CSSElixir;HTML/CSSPostgreSQLPostgreSQLNaNNaNNaNOther(s):NaNNaNVim;Visual Studio CodeLinux-basedI do not use containersNaNNaNYesYesYesRedditIn real life (in person)Username2011A few times per weekFind answers to specific questions;Learn how t...6-10 times per weekThey were about the sameNaNYesLess than once per month or monthlyYesNo, I've heard of them, but I am not part of a...NeutralJust as welcome now as I felt last yearTech meetups or events in your area;Courses on...28.0ManNoStraight / HeterosexualNaNYesAppropriate in lengthNeither easy nor difficult
4I am a developer by professionNoNeverThe quality of OSS and closed source software ...Employed full-timeUnited StatesNoBachelor’s degree (BA, BS, B.Eng., etc.)Computer science, computer engineering, or sof...Taken an online course in programming or softw...100 to 499 employeesDeveloper, full-stack316Less than 1 yearVery satisfiedSlightly satisfiedVery confidentNoNot sureI am not interested in new job opportunitiesLess than a year agoWrite code by hand (e.g., on a whiteboard);Int...NoLanguages, frameworks, and other technologies ...I was preparing for a job searchUSDUnited States dollar61000.0Yearly61000.080.0There's no schedule or spec; I work on what se...NaNLess than once per month / NeverHomeA little below averageNoNaNNo, but I think we shouldDevelopers typically have the most influence o...I have little or no influenceC;C++;C#;Python;SQLC;C#;JavaScript;SQLMySQL;SQLiteMySQL;SQLiteLinux;WindowsLinux;WindowsNaNNaN.NET.NETEclipse;Vim;Visual Studio;Visual Studio CodeWindowsI do not use containersNot at allUseful for decentralized currency (i.e., Bitcoin)YesSIGHYesRedditIn real life (in person)Username2014Daily or almost dailyFind answers to specific questions;Pass the ti...1-2 times per weekStack Overflow was much faster31-60 minutesYesLess than once per month or monthlyYesNo, and I don't know what those areNo, not reallyJust as welcome now as I felt last yearTech articles written by other developers;Indu...22.0ManNoStraight / HeterosexualWhite or of European descentNoAppropriate in lengthEasy
5I am a developer by professionYesOnce a month or more oftenOSS is, on average, of HIGHER quality than pro...Employed full-timeUkraineNoBachelor’s degree (BA, BS, B.Eng., etc.)Computer science, computer engineering, or sof...Taken an online course in programming or softw...10,000 or more employeesAcademic researcher;Developer, desktop or ente...16149Very dissatisfiedSlightly dissatisfiedSomewhat confidentYesNoI am not interested in new job opportunitiesLess than a year agoWrite any code;Write code by hand (e.g., on a ...NoIndustry that I'd be working in;Languages, fra...I was preparing for a job searchUAHUkrainian hryvniaNaNNaNNaN55.0There is a schedule and/or spec (made by me or...Being tasked with non-development work;Inadequ...A few days each monthOfficeA little above averageYes, because I see value in code reviewNaNYes, it's part of our processNot sureI have little or no influenceC++;HTML/CSS;Java;JavaScript;Python;SQL;VBAHTML/CSS;Java;JavaScript;SQL;WebAssemblyCouchbase;MongoDB;MySQL;Oracle;PostgreSQL;SQLiteCouchbase;Firebase;MongoDB;MySQL;Oracle;Postgr...Android;Linux;MacOS;Slack;WindowsAndroid;Docker;Kubernetes;Linux;SlackDjango;Express;Flask;jQuery;React.js;SpringFlask;jQuery;React.js;SpringCordova;Node.jsApache Spark;Hadoop;Node.js;React NativeIntelliJ;Notepad++;VimLinux-basedOutside of work, for personal projectsNot at allNaNYesAlso YesYesFacebookIn real life (in person)UsernameI don't rememberMultiple times per dayFind answers to specific questionsMore than 10 times per weekStack Overflow was much fasterNaNYesA few times per month or weeklyNo, I knew that Stack Overflow had a job board...No, I've heard of them, but I am not part of a...Yes, definitelyJust as welcome now as I felt last yearTech meetups or events in your area;Courses on...30.0ManNoStraight / HeterosexualWhite or of European descent;MultiracialNoAppropriate in lengthEasy
df.rename(columns={'ConvertedComp':'SalaryUSD'},inplace=True)
df['SalaryUSD']
Respondent
1            NaN
2            NaN
3         8820.0
4        61000.0
5            NaN
          ...   
88377        NaN
88601        NaN
88802        NaN
88816        NaN
88863        NaN
Name: SalaryUSD, Length: 88883, dtype: float64
df['Hobbyist']
Respondent
1        Yes
2         No
3        Yes
4         No
5        Yes
        ... 
88377    Yes
88601     No
88802     No
88816     No
88863    Yes
Name: Hobbyist, Length: 88883, dtype: object
df['Hobbyist'].map({'Yes':'True','No':'False'})
Respondent
1         True
2        False
3         True
4        False
5         True
         ...  
88377     True
88601    False
88802    False
88816    False
88863     True
Name: Hobbyist, Length: 88883, dtype: object

添加/删除行和列

people = {
    "first": ["Corey", 'Jane', 'John'], 
    "last": ["Schafer", 'Doe', 'Doe'], 
    "email": ["CoreyMSchafer@gmail", 'JaneDoe@email', 'JohnDoe@email']
}
import pandas as pd
df = pd.DataFrame(people)
df
firstlastemail
0CoreySchaferCoreyMSchafer@gmail
1JaneDoeJaneDoe@email
2JohnDoeJohnDoe@email

合并列

df['first'] + ' ' + df['last']
0    Corey Schafer
1         Jane Doe
2         John Doe
dtype: object
df['full_name'] = df['first'] + ' ' + df['last']
df
firstlastemailfull_name
0CoreySchaferCoreyMSchafer@gmailCorey Schafer
1JaneDoeJaneDoe@emailJane Doe
2JohnDoeJohnDoe@emailJohn Doe

删除列

df.drop(columns=['first','last'],inplace=True)
df
emailfull_name
0CoreyMSchafer@gmailCorey Schafer
1JaneDoe@emailJane Doe
2JohnDoe@emailJohn Doe

拆分列

  • 按照空格拆分
df['full_name'].str.split(' ')
0    [Corey, Schafer]
1         [Jane, Doe]
2         [John, Doe]
Name: full_name, dtype: object
df['full_name'].str.split(' ',expand=True)
01
0CoreySchafer
1JaneDoe
2JohnDoe
df[['first','last']] = df['full_name'].str.split(' ',expand=True)
df
emailfull_namefirstlast
0CoreyMSchafer@gmailCorey SchaferCoreySchafer
1JaneDoe@emailJane DoeJaneDoe
2JohnDoe@emailJohn DoeJohnDoe

添加数据

df.append({'first':'Tony'},ignore_index=True)
emailfull_namefirstlast
0CoreyMSchafer@gmailCorey SchaferCoreySchafer
1JaneDoe@emailJane DoeJaneDoe
2JohnDoe@emailJohn DoeJohnDoe
3NaNNaNTonyNaN

合并Dataframe

people = {
    "first": ["Tony", 'Steve'], 
    "last": ["Stark", 'Rogers'], 
    "email": ["IronMan@avenge", 'Cap@avenge']
}
df2 = pd.DataFrame(people)
df2
firstlastemail
0TonyStarkIronMan@avenge
1SteveRogersCap@avenge
df.append(df2,ignore_index=True)
emailfull_namefirstlast
0CoreyMSchafer@gmailCorey SchaferCoreySchafer
1JaneDoe@emailJane DoeJaneDoe
2JohnDoe@emailJohn DoeJohnDoe
3IronMan@avengeNaNTonyStark
4Cap@avengeNaNSteveRogers
df = df.append(df2,ignore_index=True)
df
emailfull_namefirstlast
0CoreyMSchafer@gmailCorey SchaferCoreySchafer
1JaneDoe@emailJane DoeJaneDoe
2JohnDoe@emailJohn DoeJohnDoe
3IronMan@avengeNaNTonyStark
4Cap@avengeNaNSteveRogers

删除行

df.drop(index=4)
emailfull_namefirstlast
0CoreyMSchafer@gmailCorey SchaferCoreySchafer
1JaneDoe@emailJane DoeJaneDoe
2JohnDoe@emailJohn DoeJohnDoe
3IronMan@avengeNaNTonyStark
df.drop(index=[2,3])
emailfull_namefirstlast
0CoreyMSchafer@gmailCorey SchaferCoreySchafer
1JaneDoe@emailJane DoeJaneDoe
4Cap@avengeNaNSteveRogers
filt = df['last'] == 'Doe'
df.drop(index=df[filt].index)
emailfull_namefirstlast
0CoreyMSchafer@gmailCorey SchaferCoreySchafer
3IronMan@avengeNaNTonyStark
4Cap@avengeNaNSteveRogers

数据排序

people = {
    "first": ["Corey", 'Jane', 'John','Adam'], 
    "last": ["Schafer", 'Doe', 'Doe','Doe'], 
    "email": ["CoreyMSchafer@gmail", 'JaneDoe@email', 'JohnDoe@email','A@email']
}
import pandas as pd
df = pd.DataFrame(people)
df
firstlastemail
0CoreySchaferCoreyMSchafer@gmail
1JaneDoeJaneDoe@email
2JohnDoeJohnDoe@email
3AdamDoeA@email

sort_values()

df.sort_values(by='last')
firstlastemail
1JaneDoeJaneDoe@email
2JohnDoeJohnDoe@email
3AdamDoeA@email
0CoreySchaferCoreyMSchafer@gmail
  • 按照last排序
df.sort_values(by='last',ascending=False)
firstlastemail
0CoreySchaferCoreyMSchafer@gmail
1JaneDoeJaneDoe@email
2JohnDoeJohnDoe@email
3AdamDoeA@email
  • last相同时按照first排序
df.sort_values(by=['last','first'],ascending=False)
firstlastemail
0CoreySchaferCoreyMSchafer@gmail
2JohnDoeJohnDoe@email
1JaneDoeJaneDoe@email
3AdamDoeA@email
df.sort_values(by=['last','first'],ascending=[False,True])#也有inplace参数
firstlastemail
0CoreySchaferCoreyMSchafer@gmail
3AdamDoeA@email
1JaneDoeJaneDoe@email
2JohnDoeJohnDoe@email

按照索引排序

df.sort_index()
firstlastemail
0CoreySchaferCoreyMSchafer@gmail
1JaneDoeJaneDoe@email
2JohnDoeJohnDoe@email
3AdamDoeA@email
  • 某列排序
df['last'].sort_values()
1        Doe
2        Doe
3        Doe
0    Schafer
Name: last, dtype: object

df = pd.read_csv('data/survey_results_public.csv',index_col='Respondent')
pd.set_option('display.max_columns', 85)
pd.set_option('display.max_rows', 85)
df.head(3)
MainBranchHobbyistOpenSourcerOpenSourceEmploymentCountryStudentEdLevelUndergradMajorEduOtherOrgSizeDevTypeYearsCodeAge1stCodeYearsCodeProCareerSatJobSatMgrIdiotMgrMoneyMgrWantJobSeekLastHireDateLastIntFizzBuzzJobFactorsResumeUpdateCurrencySymbolCurrencyDescCompTotalCompFreqConvertedCompWorkWeekHrsWorkPlanWorkChallengeWorkRemoteWorkLocImpSynCodeRevCodeRevHrsUnitTestsPurchaseHowPurchaseWhatLanguageWorkedWithLanguageDesireNextYearDatabaseWorkedWithDatabaseDesireNextYearPlatformWorkedWithPlatformDesireNextYearWebFrameWorkedWithWebFrameDesireNextYearMiscTechWorkedWithMiscTechDesireNextYearDevEnvironOpSysContainersBlockchainOrgBlockchainIsBetterLifeITpersonOffOnSocialMediaExtraversionScreenNameSOVisit1stSOVisitFreqSOVisitToSOFindAnswerSOTimeSavedSOHowMuchTimeSOAccountSOPartFreqSOJobsEntTeamsSOCommWelcomeChangeSONewContentAgeGenderTransSexualityEthnicityDependentsSurveyLengthSurveyEase
Respondent
1I am a student who is learning to codeYesNeverThe quality of OSS and closed source software ...Not employed, and not looking for workUnited KingdomNoPrimary/elementary schoolNaNTaught yourself a new language, framework, or ...NaNNaN410NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNHTML/CSS;Java;JavaScript;PythonC;C++;C#;Go;HTML/CSS;Java;JavaScript;Python;SQLSQLiteMySQLMacOS;WindowsAndroid;Arduino;WindowsDjango;FlaskFlask;jQueryNode.jsNode.jsIntelliJ;Notepad++;PyCharmWindowsI do not use containersNaNNaNYesFortunately, someone else has that titleYesTwitterOnlineUsername2017A few times per month or weeklyFind answers to specific questions;Learn how t...3-5 times per weekStack Overflow was much faster31-60 minutesNoNaNNo, I didn't know that Stack Overflow had a jo...No, and I don't know what those areNeutralJust as welcome now as I felt last yearTech articles written by other developers;Indu...14.0ManNoStraight / HeterosexualNaNNoAppropriate in lengthNeither easy nor difficult
2I am a student who is learning to codeNoLess than once per yearThe quality of OSS and closed source software ...Not employed, but looking for workBosnia and HerzegovinaYes, full-timeSecondary school (e.g. American high school, G...NaNTaken an online course in programming or softw...NaNDeveloper, desktop or enterprise applications;...NaN17NaNNaNNaNNaNNaNNaNI am actively looking for a jobI've never had a jobNaNNaNFinancial performance or funding status of the...Something else changed (education, award, medi...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNC++;HTML/CSS;PythonC++;HTML/CSS;JavaScript;SQLNaNMySQLWindowsWindowsDjangoDjangoNaNNaNAtom;PyCharmWindowsI do not use containersNaNUseful across many domains and could change ma...YesYesYesInstagramOnlineUsername2017Daily or almost dailyFind answers to specific questions;Learn how t...3-5 times per weekStack Overflow was much faster11-30 minutesYesA few times per month or weeklyNo, I knew that Stack Overflow had a job board...No, and I don't know what those areYes, somewhatJust as welcome now as I felt last yearTech articles written by other developers;Indu...19.0ManNoStraight / HeterosexualNaNNoAppropriate in lengthNeither easy nor difficult
3I am not primarily a developer, but I write co...YesNeverThe quality of OSS and closed source software ...Employed full-timeThailandNoBachelor’s degree (BA, BS, B.Eng., etc.)Web development or web designTaught yourself a new language, framework, or ...100 to 499 employeesDesigner;Developer, back-end;Developer, front-...3221Slightly satisfiedSlightly satisfiedNot at all confidentNot sureNot sureI’m not actively looking, but I am open to new...1-2 years agoInterview with people in peer rolesNoLanguages, frameworks, and other technologies ...I was preparing for a job searchTHBThai baht23000.0Monthly8820.040.0There's no schedule or spec; I work on what se...Distracting work environment;Inadequate access...Less than once per month / NeverHomeAverageNoNaNNo, but I think we shouldNot sureI have little or no influenceHTML/CSSElixir;HTML/CSSPostgreSQLPostgreSQLNaNNaNNaNOther(s):NaNNaNVim;Visual Studio CodeLinux-basedI do not use containersNaNNaNYesYesYesRedditIn real life (in person)Username2011A few times per weekFind answers to specific questions;Learn how t...6-10 times per weekThey were about the sameNaNYesLess than once per month or monthlyYesNo, I've heard of them, but I am not part of a...NeutralJust as welcome now as I felt last yearTech meetups or events in your area;Courses on...28.0ManNoStraight / HeterosexualNaNYesAppropriate in lengthNeither easy nor difficult
df.sort_values(by=['Country','ConvertedComp'],ascending=[True,False],inplace=True)
df[['Country','ConvertedComp']].head(50)
CountryConvertedComp
Respondent
63129Afghanistan1000000.0
50499Afghanistan153216.0
39258Afghanistan19152.0
58450Afghanistan17556.0
7085Afghanistan14364.0
22450Afghanistan7980.0
48436Afghanistan4464.0
10746Afghanistan3996.0
8149Afghanistan1596.0
29736Afghanistan1116.0
28638Afghanistan0.0
722Afghanistan0.0
62168AfghanistanNaN
85715AfghanistanNaN
50767AfghanistanNaN
2782AfghanistanNaN
63019AfghanistanNaN
6417AfghanistanNaN
40000AfghanistanNaN
88731AfghanistanNaN
85825AfghanistanNaN
62525AfghanistanNaN
49702AfghanistanNaN
33178AfghanistanNaN
60946AfghanistanNaN
86362AfghanistanNaN
88582AfghanistanNaN
86932AfghanistanNaN
7353AfghanistanNaN
26340AfghanistanNaN
58760AfghanistanNaN
74386AfghanistanNaN
29045AfghanistanNaN
51859AfghanistanNaN
45854AfghanistanNaN
47110AfghanistanNaN
44403AfghanistanNaN
80926AfghanistanNaN
59560AfghanistanNaN
60569AfghanistanNaN
37802AfghanistanNaN
43106AfghanistanNaN
12310AfghanistanNaN
87091AfghanistanNaN
38308Albania187668.0
3787Albania114550.0
9270Albania74474.0
6716Albania60000.0
10303Albania57300.0
66280Albania41244.0

查看某列前10大

df['ConvertedComp'].nlargest(10)
Respondent
25983    2000000.0
87896    2000000.0
22013    2000000.0
28243    2000000.0
72732    2000000.0
78151    2000000.0
80200    2000000.0
52132    2000000.0
75561    2000000.0
32250    2000000.0
Name: ConvertedComp, dtype: float64
  • 薪资列前10大的数据
df.nlargest(10,'ConvertedComp')#df.nsmallest
MainBranchHobbyistOpenSourcerOpenSourceEmploymentCountryStudentEdLevelUndergradMajorEduOtherOrgSizeDevTypeYearsCodeAge1stCodeYearsCodeProCareerSatJobSatMgrIdiotMgrMoneyMgrWantJobSeekLastHireDateLastIntFizzBuzzJobFactorsResumeUpdateCurrencySymbolCurrencyDescCompTotalCompFreqConvertedCompWorkWeekHrsWorkPlanWorkChallengeWorkRemoteWorkLocImpSynCodeRevCodeRevHrsUnitTestsPurchaseHowPurchaseWhatLanguageWorkedWithLanguageDesireNextYearDatabaseWorkedWithDatabaseDesireNextYearPlatformWorkedWithPlatformDesireNextYearWebFrameWorkedWithWebFrameDesireNextYearMiscTechWorkedWithMiscTechDesireNextYearDevEnvironOpSysContainersBlockchainOrgBlockchainIsBetterLifeITpersonOffOnSocialMediaExtraversionScreenNameSOVisit1stSOVisitFreqSOVisitToSOFindAnswerSOTimeSavedSOHowMuchTimeSOAccountSOPartFreqSOJobsEntTeamsSOCommWelcomeChangeSONewContentAgeGenderTransSexualityEthnicityDependentsSurveyLengthSurveyEase
Respondent
25983I am a developer by professionYesLess than once per yearOSS is, on average, of HIGHER quality than pro...Employed full-timeCanadaNoBachelor’s degree (BA, BS, B.Eng., etc.)Computer science, computer engineering, or sof...Received on-the-job training in software devel...10,000 or more employeesDeveloper, full-stack8162Very satisfiedVery satisfiedSomewhat confidentNoNoI’m not actively looking, but I am open to new...3-4 years agoSolve a brain-teaser style puzzle;Interview wi...NoRemote work options;Opportunities for professi...My job status changed (promotion, new job, etc.)USDUnited States dollar65500.0Weekly2000000.045.0There is a schedule and/or spec (made by me or...Being tasked with non-development work;Meeting...A few days each monthOfficeAverageYes, because I see value in code review2.0Yes, it's part of our processDevelopers and management have nearly equal in...I have little or no influenceBash/Shell/PowerShell;C++;C#;HTML/CSS;JavaScri...Bash/Shell/PowerShell;C#;F#;Python;SQL;TypeScriptMicrosoft SQL Server;MySQLMicrosoft SQL Server;MySQLAWS;Docker;Heroku;Linux;MacOS;Raspberry Pi;Win...AWS;Docker;Linux;MacOS;WindowsAngular/Angular.jsAngular/Angular.js;Flask;React.js.NET;.NET Core;Node.js.NET Core;Node.jsNotepad++;Sublime Text;Vim;Visual Studio;Visua...WindowsDevelopment;ProductionNaNUseful for decentralized currency (i.e., Bitcoin)NoYesYesRedditIn real life (in person)Username2013Daily or almost dailyFind answers to specific questions;Learn how t...1-2 times per weekStack Overflow was much faster11-30 minutesYesLess than once per month or monthlyNo, I knew that Stack Overflow had a job board...No, and I don't know what those areNo, not reallyJust as welcome now as I felt last yearNaN24.0ManNoStraight / HeterosexualWhite or of European descentNoAppropriate in lengthEasy
87896I am a developer by professionYesLess than once per yearThe quality of OSS and closed source software ...Employed full-timeGermanyNoBachelor’s degree (BA, BS, B.Eng., etc.)Computer science, computer engineering, or sof...Taken an online course in programming or softw...2-9 employeesDeveloper, full-stack9178Very satisfiedVery satisfiedSomewhat confidentNoI am already a managerI am not interested in new job opportunitiesMore than 4 years agoWrite any code;Interview with people in senior...NoOffice environment or company culture;Diversit...Something else changed (education, award, medi...USDUnited States dollar55000.0Weekly2000000.040.0There is a schedule and/or spec (made by me or...Being tasked with non-development work;Meeting...All or almost all the time (I'm full-time remote)HomeA little above averageYes, because I see value in code review3.0No, but I think we shouldDevelopers and management have nearly equal in...I have a great deal of influenceHTML/CSS;JavaScript;PHP;SQLHTML/CSS;JavaScript;PHP;Ruby;SQL;TypeScriptMariaDB;MySQL;PostgreSQLMariaDB;MySQL;PostgreSQLWordPressNaNjQuery;Laravel;Vue.jsExpress;Laravel;Ruby on Rails;Vue.jsNaNNode.jsSublime Text;Vim;Visual Studio CodeLinux-basedI do not use containersNot at allUseful for immutable record keeping outside of...NoYesYesTwitterOnlineHandle2011Daily or almost dailyFind answers to specific questions3-5 times per weekStack Overflow was much faster0-10 minutesYesLess than once per month or monthlyNo, I knew that Stack Overflow had a job board...No, I've heard of them, but I am not part of a...No, not reallyJust as welcome now as I felt last yearTech articles written by other developers;Tech...32.0ManNoGay or LesbianWhite or of European descentNoAppropriate in lengthNeither easy nor difficult
22013I am a developer by professionYesNeverThe quality of OSS and closed source software ...Employed full-timeIndiaNoProfessional degree (JD, MD, etc.)A natural science (ex. biology, chemistry, phy...Taken an online course in programming or softw...2-9 employeesAcademic researcher;Data scientist or machine ...3263Very satisfiedVery satisfiedNaNNaNNaNI am not interested in new job opportunities3-4 years agoWrite code by hand (e.g., on a whiteboard);Com...NoFinancial performance or funding status of the...Something else changed (education, award, medi...USDUnited States dollar1500000.0Weekly2000000.050.0There's no schedule or spec; I work on what se...Inadequate access to necessary tools;Meetings;...All or almost all the time (I'm full-time remote)HomeA little below averageYes, because I see value in code review10.0Yes, it's part of our processDevelopers typically have the most influence o...I have a great deal of influenceAssembly;Bash/Shell/PowerShell;C;C++;Java;Java...Python;SwiftCassandra;Microsoft SQL Server;OracleCassandraAndroid;Arduino;Google Cloud Platform;IBM Clou...IBM Cloud or Watson;WindowsjQueryNaNTensorFlowTensorFlowVisual Studio;Visual Studio CodeWindowsDevelopmentImplementing our own cryptocurrencyUseful across many domains and could change ma...YesYesNoYouTubeOnlineScreen NameNaNA few times per weekFind answers to specific questions1-2 times per weekStack Overflow was much faster60+ minutesYesI have never participated in Q&a

本文标签: 第一部分 pandas