-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path11-pandas-conditionals.py
More file actions
20 lines (14 loc) · 960 Bytes
/
Copy path11-pandas-conditionals.py
File metadata and controls
20 lines (14 loc) · 960 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# in this tutorials, we will see how to use pandas to select a particular set of rows that pass a condition
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# We have no headers in the file, we name the columns as i and i-squared as shown below. The names will be used while plotting
df = pd.read_csv("out.txt",header=None, names=["i","i-squared"]) # the dataframe will be shown in Spyder IDE
df1 = df[df["i"]<50] # this selects only the rows where i is < 50 and stores it in df1
# you can also plot from a dataframe
df1.plot(x="i",y="i-squared") # plot df1
plt.show()
# if the file has NO header rows, you must state that explicitly
# more info at https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html
# if you want to have the full view of the dataframe, go to variable explorer in the Spyder IDE and click on the parameter df.
# A separate window will open show the file in an Excel Sheet like view.