我有多个csv,所以我使用了glob和read_csv,将每一个附加到列表中然后连接所有这些。
我的问题是如何访问列名称和小写?
编辑:
import socket
from threading import Thread
from socketserver import ThreadingMixIn
# Multithreaded Python server : TCP Server Socket Thread Pool
class ClientThread(Thread):
def __init__(self,ip,port):
Thread.__init__(self)
self.ip = ip
self.port = port
print ("[+] New server socket thread started for " + ip + ":" + str(port))
def run(self):
while True :
data = conn.recv(2048)
#data = "Echo data: " + data.decode()
print ("Server received data: ", data)
conn.send(data) # echo
# Multithreaded Python server : TCP Server Socket Program Stub
TCP_IP = '0.0.0.0'
TCP_PORT = 2004
BUFFER_SIZE = 1024 # Usually 1024, but we need quick response
tcpServer = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tcpServer.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
tcpServer.bind((TCP_IP, TCP_PORT))
threads = []
while True:
tcpServer.listen(4)
print ("Multithreaded Python server : Waiting for connections from TCP clients...")
(conn, (ip,port)) = tcpServer.accept()
newthread = ClientThread(ip,port)
newthread.start()
threads.append(newthread)
for t in threads:
t.join()
Server received data: b''
Server received data: b''
Server received data: b''
Server received data: b''
Server received data: b''
Server received data: b''
Server received data: b''
Server received data: b''
Server received data: b''
Server received data: b''
Server received data: b''
Server received data: b''
Server received data: b''
Server received data: b''
Server received data: b''
Server received data: b''
Server received data: b''
Server received data: b''
Server received data: b''
Server received data: b''
Server received data: b''
Server received data: b''
Server received data: b''
Server received data: b''
Server received da
谢谢!
答案 0 :(得分:3)
我认为你需要str.lower
:
df.columns = df.columns.str.lower()
allfiles = glob.glob("*.csv", )
dataframes = []
for file in allfiles :
df = pd.read_csv(file, sep=";", decimal=",")
df.columns = df.columns.str.lower()
dataframes.append(df)
df = pd.concat(dataframes)
答案 1 :(得分:1)
要重命名列,您可以使用rename()
method of DataFrames。
以下是一个例子:
df.rename(columns={colname:colname.lower() for colname in df.axes[1]})
这使用列名称列表(df.axes[1]
)来创建dict
旧的列名称映射到新的低级版本。然后rename()
方法返回带有重命名列的数据框的副本。
请注意,如果您希望编辑数据框而不是返回副本,rename()
会有inplace
标记。