This question already has answers here:
Delete blank rows from CSV?
(11 answers)
Closed 8 years ago.
I've seen some threads on this, but none seem to be simple. I'm looking for a simple code to remove the blank rows in a CSV using python.
Alternatively (to the duplicate question) you can consider using grep
grep -Pv ^,*$ input_file.csv > output_file.csv
e.g. any line in input_file.csv that is not either blank or solely composed of commas get redirected to output_file.csv
Related
This question already has answers here:
Pandas column access w/column names containing spaces
(6 answers)
Closed 10 months ago.
I am trying to put a condition to print the revenue which is greater or equal to certain number using Pandas in Python.
I am using the code line" df[df.Total Revenue>=6678690.38]"
I am getting the error "SyntaxError: invalid syntax." beacuse its not taking my column name(Total Revenue) with space. So how to read column if the column header is with space?
Note = df is where I am reading my file
this should work
df[df['Total Revenue']>=6678690.38]
This question already has answers here:
pandas select from Dataframe using startswith
(5 answers)
Closed 3 years ago.
It seems like straight forward thing however could not find appropriate SO answer.
I have a column called title which contain strings. I want to find out rows that starts with letter "CU".
I've tried using df.loc however It's giving me indexError,
Using regex, re.findall(r'^CU', string)
returns 'CU' instead of full name ex: 'CU abcd'. How can I get full name that starts with 'CU'?
EDIT: SORRY, I did not notice it was a duplicate question, problem solved by reading duplicate question.
You can try:
string.startswith("CU")
This question already has answers here:
str.startswith with a list of strings to test for
(3 answers)
Closed 4 years ago.
I am working on python script that splits text in different blocks based on keywords used in text.
Currently I split text into blocks with sth like this (for 1 block, others have pretty much the same strucure):
if (line.strip().lower().startswith('ключевые навыки')
or line.strip().lower().startswith('дополнительная информация')
or line.strip().lower().startswith('знания')
or line.strip().lower().startswith('личные качества')
or line.strip().lower().startswith('профессиональные навыки')
or line.strip().lower().startswith('навыки')):
But, it is possible that list of keywords is going to expand. Is there a possibility to generate multiple or statements based on some array of possible keywords?
Try this code
values=['ключевые навыки','дополнительная информация','знания']
val=True
#enter any words you want to check
while val
for i in values:
if (line.strip().lower().startswith(i)):
#whatever code you want to implement
val=False
#to exit loop
Hope it helps :)
This question already has answers here:
Convert a list with strings all to lowercase or uppercase
(13 answers)
Closed 6 years ago.
I am trying to read a text file in jupyter notebook and fetch the unique words in the file.
I am reading that file as a list and then trying to apply lower case on it. But the .lower() function doesn't work with a list. Please help with the same.
With a list of values in val you can do this:
valsLower = [item.lower() for item in vals]
This question already has answers here:
Add 'decimal-mark' thousands separators to a number
(9 answers)
Closed 8 years ago.
I am simply trying to execute the following command in Python:
print("Number is", format(49000.12345,"10.2f"))
So I would like it to print out like 49,000.12 for the number.
My teacher taught us to put a comma in "10.2f" like ",10.2f" for the thousands separator but it's not working. Could someone please tell me the correct simple way similar to that?
Thank you
See this: http://www.python.org/dev/peps/pep-0378/ It is the PEP introducing the ability into Python 2.7, 3.1 and later versions.