Yam Code
Sign up
Login
New paste
Home
Trending
Archive
English
English
Tiếng Việt
भारत
Sign up
Login
New Paste
Browse
import numpy import pandas import statsmodels.formula.api as smf import statsmodels.stats.multicomp as multi data = pandas.read_csv('ool.csv', low_memory=False) data['PPETHM'] = pandas.to_numeric(data['PPETHM'], errors='coerce') data['W2_QG_2'] = pandas.to_numeric(data['W2_QG_2'], errors='coerce') data['W2_QO1'] = pandas.to_numeric(data['W2_QO1'], errors='coerce') sub1=data[(data['PPAGECT4']>=1) & (data['PPAGECT4']<=4) & (data['W2_QG_2']==1)] sub1['W2_QG_2']=sub1['W2_QG_2'].replace(-1, numpy.nan) sub1['W2_QO1']=sub1['W2_QO1'].replace(-1, numpy.nan) recode1 = {-1: 3, 0: 2, 1: 1} sub1['PRESIDENT']= sub1['W2_QO1'].map(recode1) sub1['PRESIDENT'] = pandas.to_numeric(sub1['PRESIDENT'], errors='coerce') # W2_QO1: President Obama's election as the nation's first African American president... # W1_QA2: Do you think what happens generally to Black people in this country will have # something to do with what happens in your life? ct1 = sub1.groupby('W2_QO1').size() print (ct1) # Phân tích ANOVA model1 = smf.ols(formula='W2_QO1 ~ C(W1_QA2)', data=sub1) results1 = model1.fit() print(results1.summary()) ################################################################ sub2 = sub1[['W2_QO1', 'W1_QA2']].dropna() print('Trung bình cho w2_qo1 bởi những gì xảy ra với người da đen có liên quan đến việc Obama lên làm tổng thống') m1= sub2.groupby('W1_QA2').mean() print(m1) print('Độ lệch chuẩn cho w2_qo1 bởi những gì xảy ra với người da đen có liên quan đến việc Obama lên làm tổng thống') sd1 = sub2.groupby('W1_QA2').std() print(sd1) # ========= Biến giải thích nhiều hơn 2 loại sub3 = sub1[['W2_QO1', 'PPETHM']].dropna() print(sub3['PPETHM'].value_counts().sort_index()) # 1. Da trắng, không gốc Tây Ban Nha # 2. Da đen, không gốc Tây Ban Nha # 3. Khác, không gốc Tây Ban Nha # 4. Người gốc Tây Ban Nha # 5. 2+ chủng tộc khác, không gốc Tây Ban Nha model2 = smf.ols(formula='W2_QO1 ~ C(PPETHM)', data=sub3).fit() print(model2.summary()) print ('Trung bình cho w2_qo1 theo chủng tộc') m2= sub3.groupby('PPETHM').mean() print (m2) print (' Độ lệch chuẩn cho w2_qo1 theo chủng tộc') sd2 = sub3.groupby('PPETHM').std() print (sd2) ## Phân tích sâu mc1 = multi.MultiComparison(sub3['W2_QO1'], sub3['PPETHM']) res1 = mc1.tukeyhsd() print(res1.summary())
Paste Settings
Paste Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax Highlighting :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Paste Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create New Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English
Tiếng Việt
भारत