- How to Get Last Few Lines from a CSV File Using Windows PowerShell
- How to Create New Column Using Existing Two or More Columns in Pandas with apply Function
- How to Convert a Python File to Jupyter Notebook
- Useful Links
- Linux Related
I had to see last few rows of a large CSV file (>16 GB); it was too large to open in Excel. So I obtained the last few rows from that file and wrote it to another file using Windows PowerShell. Input.csv is my large file and Output.csv is the output file.
- Use of get-content (or type) is obtained from this link.
- Use of ASCII encoding is obtained from this link the third answer, by Lenny.
- Use of Append is obtained from this link.
type -First 1 Input.csv | out-file "Output.csv" -encoding ASCII # Getting heading
type -last 1000 Input.csv | out-file "Output.csv" -encoding ASCII -Append # Getting last 1000 rows
Suppose we have 3 columns in the data named A, B, C. Now, we want to create a column of tag, such that for each row its value will be A if value in collumn A is maxium, B if value in column B is maximum or value C if value in column C is maximum.
# Function to derive tag
def tag_function(a, b, c):
maximum_value = max(a, b, c)
if maximum_value == a:
tbr = "A"
elif maximum_value == b:
tbr = "B"
elif maximum_value == c:
tbr = "C"
return tbr
data["tag"] = data[["A", "B", "C"]].apply(lambda x:tag_function(x["A"], x["B"], x["C"]), axis = 1)
I have written this following this link. Suppose A.py is the file you want to convert to notebook.
- Step 1 (Optional): Put #%% (Do not put space after it, it will not work) before the chunk of code you want to put in a cell in notebook.
- Step 2: Install ipynb-py-convert.
For base Python:For Condapip install ipynb-py-convert
conda install -c defaults -c conda-forge ipynb-py-convert
- Step 3: Write this command in the Command Prompt or Anaconda Prompt
ipynb-py-convert A.py A.ipynb
- Basics of writing Markdown files by Microsoft. Link