i have a file with this information in it
i would like to create a new file with python and write only the stocks which has marketcap below 600.
i can't seem to split the lists in a way that i only get marketcap values.
this is as far as i got
file1 = open("stocks.txt","r ")
my_list = file1.readlines()
for i in my_list:
print(i)
if anyoune could help it would be much apreciated
CodePudding user response:
import pandas as pd
df = pd.read_csv("stocks.txt", " ") # Read file with space as delimiter
df.loc[(df["market_cap"] < 600)] # Select rows where "market_cap" is less than 600
CodePudding user response:
You can use Pandas to achieve this task by handling the file a CSV, and filter the lines based on your condition.
import pandas as pd
df = pd.read_csv('stocks.txt', set=' ', index_com='stock')
df[df.market_cap < 600].to_csv('stocks_mc_below_600.csv')