<jupyter_start><jupyter_text>pd.SeriesOne-Dimentional container like Python's list. each element should be the same `dtype`. If you mix the number and the string, then `dtype` will be `object`.<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

pd.Series([42, "the answer"])
sr = pd.Series([42, "the answer"], index=["one", "two"])
sr.loc["one"]
sr.iloc[0]
sr.index
sr.index.values
sr.values<jupyter_output><empty_output><jupyter_text>pd.DataFrame- index = row label name- columns = column name<jupyter_code>df = pd.DataFrame({"Name": ["Taro", "Bob"], "Age": [20, 30], "Nationality": ["Japan", "USA"]}, index=["Taro", "Bob"], columns=["Name", "Nationality", "Age"])
df
# df.loc returns Series
type(df.loc["Taro"])
df.loc["Taro"]
df.keys() == df.columns<jupyter_output><empty_output><jupyter_text>Series methods and attributes- attributes: loc, iloc, dtypes, T, shape, size, values- methods: append(), corr(), cov(), describe(), get_values(), hist(), min(), max(), median(), mean(), mode(), quantile(), replace(), sample(), sort_values(), transpose(), unique()<jupyter_code>DATADIR = "/Users/tomoya/src/github.com/chendaniely/pandas_for_everyone/data/"

scientists = pd.read_csv(DATADIR + "scientists.csv")
scientists["Age"].describe()
# We can subset values with a vector of Booleans
scientists[scientists["Age"] > 50]
# Vectors with common index labels are automatically aligned

ages = scientists["Age"]
ages_rev = ages.sort_values(ascending=True)
ages * 2
# Note that we get the same result with above, instead of adding the first and the last
ages + ages_rev
# Add new column

scientists["born_at"] = pd.to_datetime(scientists['Born'], format='%Y-%m-%d')
scientists
# Directly modify the column

rand = scientists["Age"].sample(len(scientists["Age"]), random_state=42)
rand
# We need to call reset_index() to remove the original index and `drop=True` to get only the values
scientists["Age"] = rand.reset_index(drop=True)
scientists
scientists.drop(["Age"], inplace=True, axis=1)
scientists
# Feather format can be used to interface with R
# -- but do not use it for the persistence purpose.<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15564738292011018, 'fraction_numerical': 0.006887052341597796, 'mean_word_length': 6.41156462585034, 'pattern_counts': {'":': 3, '<': 13, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '295049', 'license': 'MIT', 'n_tokens_mistral': 745, 'n_tokens_neox': 707, 'n_words': 216, 'path': 'pandas_for_everyone/2_DataStructure.ipynb', 'repo_name': 'o3c9/playgrounds', 'size': '2178'}