Python Listing

These are just some hopefully useful hints when using Python with Pandas.

Object How to Coding Hint Link to Details
Strings Modify myString[0:4] + “-“ + myString[4:6] Strings
Float round a larger currency value to thousands int(round(myFloat,-3)) Float
Arrays create an array with 10 integers list(range(0,10)) Arrays
Arrays reverse the order of its elements myArr[::-1].reverse() Arrays
Arrays loop over array and get index for i, city in enumerate(myCities): Arrays
Dictionaries create a dict in a loop myDict[city[:1]] = city Dictionaries
Dictionaries loop over array for key, value in myDict.items(): Dictionaries
Comprehensions get list elements for a condition [city for city in myCities if “r” in city] Comprehensions
Files Find file or root, dirs, files in os.walk(path): Files
Files create folder os.mkdir(path) Files

This table was generated using a dataframe. Find here explanations about Python.

Copyright 2021-2022