Skip to content

Instantly share code, notes, and snippets.

@twolfson
Last active July 19, 2020 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twolfson/746b064c9f379c2dceaa8aa1fa4f93c8 to your computer and use it in GitHub Desktop.
Save twolfson/746b064c9f379c2dceaa8aa1fa4f93c8 to your computer and use it in GitHub Desktop.
Exploration gist for pandas
# 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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment