Giter Club home page Giter Club logo

learinings's Introduction

Table of Contents

  1. How to Get Last Few Lines from a CSV File Using Windows PowerShell
  2. How to Create New Column Using Existing Two or More Columns in Pandas with apply Function
  3. How to Convert a Python File to Jupyter Notebook
  4. Useful Links
  5. Linux Related
    1. How to generate PDF from .tex files in Ubuntu.

How to Get Last Few Lines from a CSV File Using Windows PowerShell

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

How to Create New Column Using Existing Two or More Columns in Pandas with apply Function

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)

How to Convert a Python File to Jupyter Notebook

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:
    pip install ipynb-py-convert
    
    For Conda
    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

Useful Links

  • Basics of writing Markdown files by Microsoft. Link

Linux Related

How to generate PDF from Latex files in Ubuntu

learinings's People

Contributors

kkhatua98 avatar kaustavkhatua avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.