<jupyter_start><jupyter_text>import pandas as pd<jupyter_code>url = 'https://tinyurl.com/titanic-csv'
dataframe = pd.read_csv(url)
dataframe.head(5)
dataframe = pd.DataFrame()
dataframe['Name'] = ['<NAME>', '<NAME>']
dataframe['Age'] = [28, 35]
dataframe['Locksmith'] = [True, False]
dataframe
dataframe['Name'] = ['<NAME>', '<NAME>']
dataframe['Age'] = [38, 25]
dataframe['Driver'] = [True, False]
dataframe
new_person = pd.Series(['<NAME>', 40, True], index=['Name', 'Age', 'Driver'])
dataframe.append(new_person, ignore_index=True)
url = 'https://tinyurl.com/titanic-csv'
dataframe = pd.read_csv(url)
dataframe.head(2)
dataframe.shape

dataframe.describe()
dataframe.iloc[0]
dataframe.iloc[1:4]
dataframe.iloc[:4]
dataframe = dataframe.set_index(dataframe['Name'])
dataframe.loc['Allen, <NAME>']
dataframe[dataframe['Sex'] == 'female'].head(2)
dataframe[(dataframe['Sex'] == 'female') & (dataframe['Age'] >= 65)]

dataframe['Sex'].replace("female", "Woman").head(2)
dataframe['Sex'].replace(["female", "male"], ["Woman", "Man"]).head(5)
dataframe.replace(1, "One").head(2)
dataframe.rename(columns={'PClass': 'Passenger Class'}).head(2)
dataframe.rename(columns={'PClass': 'Passenger Class', 'Sex': 'Gender'}).head(2)
import collections
column_names = collections.defaultdict(str)
for name in dataframe.columns:
    column_names[name]
column_names
print('Maximum:', dataframe['Age'].max())
print('Minimum:', dataframe['Age'].min())
print('Mean:', dataframe['Age'].mean())
print('Sum:', dataframe['Age'].sum())
print('Count:', dataframe['Age'].count())
dataframe.count()
dataframe['Sex'].unique()
dataframe['Sex'].value_counts()
dataframe['PClass'].value_counts()
dataframe['PClass'].nunique()
dataframe[dataframe['Age'].isnull()].head(2)
import numpy as np
dataframe['Sex'] = dataframe['Sex'].replace('male', np.nan)
dataframe = pd.read_csv(url, na_values=[np.nan, 'NONE', -999])
dataframe
dataframe.drop('Age', axis=1).head(2)
dataframe.drop(['Age', 'Sex'], axis=1).head(2)
dataframe.drop(dataframe.columns[1], axis=1).head(2)
dataframe_name_dropped = dataframe.drop(dataframe.columns[0], axis=1)
dataframe_name_dropped 
dataframe[dataframe['Sex'] != 'male'].head(2)
dataframe[dataframe['Name'] != 'Allison, <NAME>'].head(2)
dataframe[dataframe.index != 0].head(2)
dataframe.drop_duplicates().head(2)
print("Number Of Rows In The Original DataFrame:", len(dataframe))
print("Number Of Rows After Deduping:", len(dataframe.drop_duplicates()))
dataframe.drop_duplicates(subset=['Sex'])
dataframe.drop_duplicates(subset=['Sex'], keep='last')
dataframe.groupby('Sex').mean()
dataframe.groupby('Sex')
dataframe.groupby('Survived')['Name'].count()
dataframe.groupby(['Sex','Survived'])['Age'].mean()
import pandas as pd
import numpy as np
time_index = pd.date_range('06/06/2017', periods=100000, freq='30S')
dataframe = pd.DataFrame(index=time_index)
dataframe['Sale_Amount'] = np.random.randint(1, 10, 100000)
dataframe.resample('W').sum()
dataframe.head(3)
dataframe.resample('2W').mean()
dataframe.resample('M').count()
dataframe.resample('M', label='left').count()
dataframe = pd.read_csv(url)
for name in dataframe['Name'][0:2]:
    print(name.upper())
[name.upper() for name in dataframe['Name'][0:2]]
def uppercase(x):
    return x.upper()
dataframe['Name'].apply(uppercase)[0:2]
dataframe.groupby('Sex').apply(lambda x: x.count())
import pandas as pd

# Create DataFrame
data_a = {'id': ['1', '2', '3'],
          'first': ['Alex', 'Amy', 'Allen'],
          'last': ['Anderson', 'Ackerman', 'Ali']}
dataframe_a = pd.DataFrame(data_a, columns = ['id', 'first', 'last'])

# Create DataFrame
data_b = {'id': ['4', '5', '6'],
          'first': ['Billy', 'Brian', 'Bran'],
          'last': ['Bonder', 'Black', 'Balwner']}
dataframe_b = pd.DataFrame(data_b, columns = ['id', 'first', 'last'])

# Concatenate DataFrames by rows
pd.concat([dataframe_a, dataframe_b], axis=0)
pd.concat([dataframe_a, dataframe_b], axis=1)
row = pd.Series([10, 'Chris', 'Chillon'], index=['id', 'first', 'last'])

# Append row
dataframe_a.append(row, ignore_index=True)
employee_data = {'employee_id': ['1', '2', '3', '4'],
                 'name': ['<NAME>', '<NAME>', '<NAME>',
                 '<NAME>']}
dataframe_employees = pd.DataFrame(employee_data, columns = ['employee_id',
                                                              'name'])

# Create DataFrame
sales_data = {'employee_id': ['3', '4', '5', '6'],
              'total_sales': [23456, 2512, 2345, 1455]}
dataframe_sales = pd.DataFrame(sales_data, columns = ['employee_id',
                                                      'total_sales'])

# Merge DataFrames
pd.merge(dataframe_employees, dataframe_sales, on='employee_id')
pd.merge(dataframe_employees, dataframe_sales, on='employee_id', how='outer')
pd.merge(dataframe_employees, dataframe_sales, on='employee_id', how='left')
pd.merge(dataframe_employees,
         dataframe_sales,
         left_on='employee_id',
         right_on='employee_id')
text_data = ["   Visual Analytics. By <NAME>     ",
             "Walking and Running. By <NAME>",
             "    Night Never Sleeps. By Strange Fellow   "]
strip_whitespace = [string.strip() for string in text_data]
strip_whitespace
remove_periods = [string.replace(".", "") for string in strip_whitespace]
remove_periods
def capitalizer(string: str) -> str:
    return string.upper()
[capitalizer(string) for string in remove_periods]
import re
def replace_letters_with_X(string: str) -> str:
    return re.sub(r"[a-zA-Z]", "X", string)
[replace_letters_with_X(string) for string in remove_periods]
from bs4 import BeautifulSoup
html = """
       <div class='full_name'><span style='font-weight:bold'>
       Hopkins</span> John</div>"
       """
soup = BeautifulSoup(html, "lxml")
soup.find("div", { "class" : "full_name" }).text
import unicodedata
import sys
text_data = ['Hi!!!! I. Like. This. Movie....',
             '100% Agree!!!! #LikeIT',
             'Correct?!?!']
text_data
punctuation = dict.fromkeys(i for i in range(sys.maxunicode)
                            if unicodedata.category(chr(i)).startswith('P'))
[string.translate(punctuation) for string in text_data]
from nltk.tokenize import word_tokenize
string = "The quick brown fox jumps over the lazy dog. Tomorrow never comes."
word_tokenize(string)
from nltk.tokenize import sent_tokenize
sent_tokenize(string)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19184952978056427, 'fraction_numerical': 0.018025078369905956, 'mean_word_length': 5.225365853658537, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 25, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '563580', 'license': 'MIT', 'n_tokens_mistral': 2311, 'n_tokens_neox': 2185, 'n_words': 440, 'path': 'Data Science Pandas.ipynb', 'repo_name': 'Kpatel07/Data-Science-', 'size': '6459'}