Not logged in
Talk
Contributions
Create account
Log in
Navigation
Main page
About
People
Publications
Teaching
Resources
Research Blog
Wiki Functions
Recent changes
Help
Licensing
Page
Discussion
Edit
View history
Editing
Community Data Science Course (Spring 2023)/Week 7 lecture notes
(section)
From CommunityData
Jump to:
navigation
,
search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Our first real data frame == If your data is already in TSV, you can import it with something like: <syntaxhighlight lang="python"> rockband_revs = pd.read_csv("rock_bands_wp_revisions.tsv", delimiter="\t") </syntaxhighlight> There is also a read_json() function but it's a bit less magic that you might like. We'll come back and I'll show you how to build it up on your own. * <code>df.head()</code> * <code>df.tail()</code> * <code>df.shape()</code> * we can getting one column by treating it like a dictionary (or multiple by passing in a list of columns! * they also have indexes (although we'll skip that for now) * we can get a cell using <code>.iloc[]</code> (notice the square brackets because it's indexing in), which also takes slice notations Every columns of a data.frame is just a series! This means: * <code>value_counts()</code> * <code>.hist()</code> Pandas series can be used in booleans: * we can use booleans to filter! ** e.g., we can get a list of revisions for a particular <tt>title</tt> (i.e., subsetting) * check the type of minor and anon (wow, pandas is smart!) ** we can use those as subsets too ** and we can combine them with <code>and</code>, <code>or</code>, or <code>not</code>! ** and if only want a couple columns, we can combine them here
Summary:
Please note that all contributions to CommunityData are considered to be released under the Attribution-Share Alike 3.0 Unported (see
CommunityData:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:
Cancel
Editing help
(opens in new window)
Tools
What links here
Related changes
Special pages
Page information