python-3.x

How to convert xml file to csv output in python?

旧街凉风 提交于 2021-02-10 08:02:02
问题 I have a basic XML file that is being pulled from a database outside of my control. <?xml version="1.0" encoding="utf-8"?> <data> <Job1Start><Time>20200202055415725</Time></Job1Start> <Job1End><Time>20200202055423951</Time></Job1End> <Job2Start><Time>20200202055810390</Time></Job2Start> <Job3Start><Time>20200202055814687</Time></Job3Start> <Job2End><Time>20200202055819000</Time></Job2End> <Job3End><Time>20200202055816708</Time></Job3End> </data> I'm looking to get the following output in a

How to sort latin after local language in python 3?

假装没事ソ 提交于 2021-02-10 08:01:49
问题 There are many situations where the user's language is not a " latin " script (examples include: Greek, Russian, Chinese). In most of these cases a sorting is done by first sorting the special characters and numbers (numbers in local language though...), secondly the words in the local language-script at the end, any non native characters such as French, English or German "imported" words, in a general utf collation. Or even more specific for the rest...: is it possible to select the sort

Python combining all csv files in a directory and order by date time

我怕爱的太早我们不能终老 提交于 2021-02-10 07:25:48
问题 I have 2 years worth of daily data split into monthly files. I would like to combine all of this data into one file ordered by date and time. The code I am using combines all the files, but not in order. Code I am using import pandas as pd import glob, os import csv inputdirectory = input('Enter the directory: ') df_list = [] for filename in sorted(glob.glob(os.path.join(inputdirectory,"*.csv*"))): df_list.append(pd.read_csv(filename)) full_df = pd.concat(df_list) full_df.to_csv('totalsum.csv

hickle NameError: name 'file' is not defined

柔情痞子 提交于 2021-02-10 07:25:29
问题 please explain to me why this error getting for me. I have install python 3.5 in ubuntu import os import hickle as hkl import numpy as np array_obj = np.ones(32768, dtype='float32') hkl.dump(array_obj, 'test.hkl', mode='w') the result is Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\Admin\AppData\Local\Programs\Python\Python35\lib\site-packages\hickle.py", line 308, in dump h5f = file_opener(file_obj, mode, track_times) File "C:\Users\Admin\AppData

How to count number of substrings in python, if substrings overlap?

…衆ロ難τιáo~ 提交于 2021-02-10 07:25:10
问题 The count() function returns the number of times a substring occurs in a string, but it fails in case of overlapping strings. Let's say my input is: ^_^_^-_- I want to find how many times ^_^ occurs in the string. mystr=input() happy=mystr.count('^_^') sad=mystr.count('-_-') print(happy) print(sad) Output is: 1 1 I am expecting: 2 1 How can I achieve the desired result? 回答1: New Version You can solve this problem without writing any explicit loops using regex. As @abhijith-pk's answer

Rename columns regex, keep name if no match

早过忘川 提交于 2021-02-10 07:15:23
问题 data = {'First_Column': [1,2,3], 'Second_Column': [1,2,3], '\First\Mid\LAST.Ending': [1,2,3], 'First1\Mid1\LAST1.Ending': [1,2,3]} df = pd.DataFrame(data) First_Column Second_Column \First\Mid\LAST.Ending First1\Mid1\LAST1.Ending 0 1 1 1 1 1 2 2 2 2 2 3 3 3 3 I want to rename the columns as follows: First_Column Second_Column LAST LAST1 0 1 1 1 1 1 2 2 2 2 2 3 3 3 3 So i tried: df.columns.str.extract(r'([^\\]+)\.Ending') 0 0 NaN 1 NaN 2 LAST 3 LAST1 and col = df.columns.tolist() for i in col

Rename columns regex, keep name if no match

家住魔仙堡 提交于 2021-02-10 07:15:08
问题 data = {'First_Column': [1,2,3], 'Second_Column': [1,2,3], '\First\Mid\LAST.Ending': [1,2,3], 'First1\Mid1\LAST1.Ending': [1,2,3]} df = pd.DataFrame(data) First_Column Second_Column \First\Mid\LAST.Ending First1\Mid1\LAST1.Ending 0 1 1 1 1 1 2 2 2 2 2 3 3 3 3 I want to rename the columns as follows: First_Column Second_Column LAST LAST1 0 1 1 1 1 1 2 2 2 2 2 3 3 3 3 So i tried: df.columns.str.extract(r'([^\\]+)\.Ending') 0 0 NaN 1 NaN 2 LAST 3 LAST1 and col = df.columns.tolist() for i in col

Deleting all documents in CouchDB

好久不见. 提交于 2021-02-10 07:14:51
问题 I have a database and I want to truncate all records, I know it is possible to just add a _deleted key to every document or call db.delete() on CouchDB-python library. I am using the delete of couchdb-python but it does not seem to work when I fetch all the documents and then call .delete on each document excluding design documents. Here is my code. docs = get_db().view('_all_docs', include_docs=True) for i in docs: if not(i['id'].startswith('_')): get_db().delete(i) This is the error.

Deleting all documents in CouchDB

风流意气都作罢 提交于 2021-02-10 07:12:04
问题 I have a database and I want to truncate all records, I know it is possible to just add a _deleted key to every document or call db.delete() on CouchDB-python library. I am using the delete of couchdb-python but it does not seem to work when I fetch all the documents and then call .delete on each document excluding design documents. Here is my code. docs = get_db().view('_all_docs', include_docs=True) for i in docs: if not(i['id'].startswith('_')): get_db().delete(i) This is the error.

Deleting all documents in CouchDB

有些话、适合烂在心里 提交于 2021-02-10 07:11:45
问题 I have a database and I want to truncate all records, I know it is possible to just add a _deleted key to every document or call db.delete() on CouchDB-python library. I am using the delete of couchdb-python but it does not seem to work when I fetch all the documents and then call .delete on each document excluding design documents. Here is my code. docs = get_db().view('_all_docs', include_docs=True) for i in docs: if not(i['id'].startswith('_')): get_db().delete(i) This is the error.