In [2]:
import pandas as pd

In [6]:
filepath = "/Users/nityansuman/__data__/sarcasm_dataset/reddit-sarcastic-comment-dataset.csv"

In [7]:
dataframe = pd.read_csv(filepath)

In [8]:
type(dataframe)


Out[8]:
pandas.core.frame.DataFrame

In [9]:
dataframe.head()


Out[9]:
label comment author subreddit score ups downs date created_utc parent_comment
0 0 NC and NH. Trumpbart politics 2 -1 -1 2016-10 2016-10-16 23:55:23 Yeah, I get that argument. At this point, I'd ...
1 0 You do know west teams play against west teams... Shbshb906 nba -4 -1 -1 2016-11 2016-11-01 00:24:10 The blazers and Mavericks (The wests 5 and 6 s...
2 0 They were underdogs earlier today, but since G... Creepeth nfl 3 3 0 2016-09 2016-09-22 21:45:37 They're favored to win.
3 0 This meme isn't funny none of the "new york ni... icebrotha BlackPeopleTwitter -8 -1 -1 2016-10 2016-10-18 21:03:47 deadass don't kill my buzz
4 0 I could use one of those tools. cush2push MaddenUltimateTeam 6 -1 -1 2016-12 2016-12-30 17:00:13 Yep can confirm I saw the tool they use for th...

In [12]:
dataframe.shape


Out[12]:
(1010826, 10)

In [18]:
dataframe.columns


Out[18]:
Index(['label', 'comment', 'author', 'subreddit', 'score', 'ups', 'downs',
       'date', 'created_utc', 'parent_comment'],
      dtype='object')

In [19]:
type(dataframe.columns)


Out[19]:
pandas.core.indexes.base.Index

In [20]:
for x in dataframe.columns:
    print(x)


label
comment
author
subreddit
score
ups
downs
date
created_utc
parent_comment

In [21]:
columns = list(dataframe.columns)
print(columns)


['label', 'comment', 'author', 'subreddit', 'score', 'ups', 'downs', 'date', 'created_utc', 'parent_comment']

In [24]:
"Hello world".split()


Out[24]:
['Hello', 'world']

In [35]:
dataframe[["label", "comment"]]


Out[35]:
label comment
0 0 NC and NH.
1 0 You do know west teams play against west teams...
2 0 They were underdogs earlier today, but since G...
3 0 This meme isn't funny none of the "new york ni...
4 0 I could use one of those tools.
5 0 I don't pay attention to her, but as long as s...
6 0 Trick or treating in general is just weird...
7 0 Blade Mastery+Masamune or GTFO!
8 0 You don't have to, you have a good build, buy ...
9 0 I would love to see him at lolla.
10 0 I think a significant amount would be against ...
11 0 Damn I was hoping God was real
12 0 They have an agenda.
13 0 Great idea!
14 0 Ayy bb wassup, it makes a bit more sense in co...
15 0 what the fuck
16 0 noted.
17 0 because it's what really bothers him... and it...
18 0 why you fail me, my precious?
19 0 Pre-Flashpoint Clark and Lois.
20 0 She hugs him back tightly, burying her head in...
21 0 At this point they're so stable I could build ...
22 0 Conservatism as an ideology is for sure a reac...
23 0 Maybe not control, but certainly that is evide...
24 0 Mine auto renewed without asking me the other ...
25 0 466
26 0 Jesus is a FNAF fan confirmed
27 0 This would make me cry.
28 0 At first I thought it was instructions on fixi...
29 0 This guy, there's no way he isn't trolling, ri...
... ... ...
1010796 1 ZOMG!
1010797 1 Clearly the death sentence would have avoided ...
1010798 1 Wow, that was quick.
1010799 1 del *.xml
1010800 1 I like the kid holding up the sign that says "...
1010801 1 Yes, and there's no such thing as mental illne...
1010802 1 Thank you, Glen Beck, Rush Limbaugh, Sean Hann...
1010803 1 you and your facts...
1010804 0 so cool.
1010805 1 What fine, upstanding young gentlemen.
1010806 1 Good luck with that.
1010807 1 The real question is why God hasn't killed Bar...
1010808 1 Women shouldn't lead men anyway... it's in the...
1010809 1 Being in a region that is that hot and being f...
1010810 1 but he's totally racist
1010811 1 Thank you unions.
1010812 1 Foxnews is the most accurate reporting service...
1010813 1 OMG, WHAT'S NEXT, KISSES?
1010814 1 nono, he'll go back to 1985 to stop the Syrian...
1010815 0 Who said I didn't have a big dick?
1010816 1 forgot to add
1010817 1 So *that's* why I can point my finger and have...
1010818 1 OH SWEET ANOTHER GUITAR HERO CLONE
1010819 1 oh wow, I have never seen this before.
1010820 1 :O
1010821 1 I'm sure that Iran and N. Korea have the techn...
1010822 1 whatever you do, don't vote green!
1010823 1 Perhaps this is an atheist conspiracy to make ...
1010824 1 The Slavs got their own country - it is called...
1010825 1 values, as in capitalism .. there is good mone...

1010826 rows × 2 columns


In [36]:
dataframe.iloc[0]


Out[36]:
label                                                             0
comment                                                  NC and NH.
author                                                    Trumpbart
subreddit                                                  politics
score                                                             2
ups                                                              -1
downs                                                            -1
date                                                        2016-10
created_utc                                     2016-10-16 23:55:23
parent_comment    Yeah, I get that argument. At this point, I'd ...
Name: 0, dtype: object

In [37]:
dataframe.iloc[0:3]


Out[37]:
label comment author subreddit score ups downs date created_utc parent_comment
0 0 NC and NH. Trumpbart politics 2 -1 -1 2016-10 2016-10-16 23:55:23 Yeah, I get that argument. At this point, I'd ...
1 0 You do know west teams play against west teams... Shbshb906 nba -4 -1 -1 2016-11 2016-11-01 00:24:10 The blazers and Mavericks (The wests 5 and 6 s...
2 0 They were underdogs earlier today, but since G... Creepeth nfl 3 3 0 2016-09 2016-09-22 21:45:37 They're favored to win.

In [43]:
dataframe.loc[0:3, ["comment"]]


Out[43]:
comment
0 NC and NH.
1 You do know west teams play against west teams...
2 They were underdogs earlier today, but since G...
3 This meme isn't funny none of the "new york ni...

In [46]:
dataframe.iloc[0:3, 1:2]


Out[46]:
comment
0 NC and NH.
1 You do know west teams play against west teams...
2 They were underdogs earlier today, but since G...

In [48]:
# dataframe.iloc[0:3, ["comment"]] # wrong

In [49]:
dataframe.dtypes


Out[49]:
label              int64
comment           object
author            object
subreddit         object
score              int64
ups                int64
downs              int64
date              object
created_utc       object
parent_comment    object
dtype: object

In [50]:
dataframe.shape


Out[50]:
(1010826, 10)

In [51]:
temp_df = dataframe.iloc[0:100, ::].copy()
temp_df.head(5)


Out[51]:
label comment author subreddit score ups downs date created_utc parent_comment
0 0 NC and NH. Trumpbart politics 2 -1 -1 2016-10 2016-10-16 23:55:23 Yeah, I get that argument. At this point, I'd ...
1 0 You do know west teams play against west teams... Shbshb906 nba -4 -1 -1 2016-11 2016-11-01 00:24:10 The blazers and Mavericks (The wests 5 and 6 s...
2 0 They were underdogs earlier today, but since G... Creepeth nfl 3 3 0 2016-09 2016-09-22 21:45:37 They're favored to win.
3 0 This meme isn't funny none of the "new york ni... icebrotha BlackPeopleTwitter -8 -1 -1 2016-10 2016-10-18 21:03:47 deadass don't kill my buzz
4 0 I could use one of those tools. cush2push MaddenUltimateTeam 6 -1 -1 2016-12 2016-12-30 17:00:13 Yep can confirm I saw the tool they use for th...

In [52]:
temp_df.shape


Out[52]:
(100, 10)

In [57]:
for i, row in temp_df.iterrows():
    print(row["comment"])
    break


NC and NH.

In [58]:
temp_df.columns


Out[58]:
Index(['label', 'comment', 'author', 'subreddit', 'score', 'ups', 'downs',
       'date', 'created_utc', 'parent_comment'],
      dtype='object')

In [62]:
temp_df = temp_df.rename(columns={"label": "new_label", "created_utc": "something"})
temp_df.columns


Out[62]:
Index(['new_label', 'comment', 'author', 'subreddit', 'score', 'ups', 'downs',
       'date', 'something', 'parent_comment'],
      dtype='object')

In [63]:
temp_df.head(5)


Out[63]:
new_label comment author subreddit score ups downs date something parent_comment
0 0 NC and NH. Trumpbart politics 2 -1 -1 2016-10 2016-10-16 23:55:23 Yeah, I get that argument. At this point, I'd ...
1 0 You do know west teams play against west teams... Shbshb906 nba -4 -1 -1 2016-11 2016-11-01 00:24:10 The blazers and Mavericks (The wests 5 and 6 s...
2 0 They were underdogs earlier today, but since G... Creepeth nfl 3 3 0 2016-09 2016-09-22 21:45:37 They're favored to win.
3 0 This meme isn't funny none of the "new york ni... icebrotha BlackPeopleTwitter -8 -1 -1 2016-10 2016-10-18 21:03:47 deadass don't kill my buzz
4 0 I could use one of those tools. cush2push MaddenUltimateTeam 6 -1 -1 2016-12 2016-12-30 17:00:13 Yep can confirm I saw the tool they use for th...

In [64]:
a = [1, 2, 3, 4]

In [65]:
a


Out[65]:
[1, 2, 3, 4]

In [66]:
b = [2, 3, 4, 6]

In [67]:
b


Out[67]:
[2, 3, 4, 6]

In [68]:
a.extend(b)

In [69]:
a


Out[69]:
[1, 2, 3, 4, 2, 3, 4, 6]

In [ ]: