Last active
July 19, 2020 19:02
-
-
Save twolfson/746b064c9f379c2dceaa8aa1fa4f93c8 to your computer and use it in GitHub Desktop.
Exploration gist for pandas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load in our dependencies | |
import pandas | |
import numpy | |
# Define our main function | |
def main(): | |
# Create a pandas dataframe | |
# https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html | |
# `numpy.array()` syntax | |
# df = pandas.DataFrame([ | |
# ["foo", "bar"], | |
# ["baz", "bat"], | |
# ]) | |
# print(df) | |
# Create a DataFrame with a table of x by y with a name column | |
df = pandas.DataFrame() | |
for x in range(1, 9+1): | |
df[x] = ["x"] * 20 | |
df["name"] = range(0, 20) | |
df = df.set_index("name") | |
# Overwrite some values | |
df.loc[2, 4] = "o" | |
df.loc[7, 2] = "o" | |
print(df) | |
# If we're being run directly, then run `main` | |
if __name__ == "__main__": | |
import sys | |
if sys.version_info.major < 3: | |
raise AssertionError("Expected Python to be Python@3 or greater but it was Python@{}".format( | |
sys.version_info.major)) | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pandas==1.0.5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment